From 5d91c3bcfc2383c909c95edd376a6fd43f4c20a0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 31 Mar 2019 01:33:56 +0900 Subject: [PATCH] Fix replay handler nullref crashes --- .../Replays/OsuFramedReplayInputHandler.cs | 2 +- .../Replays/FramedReplayInputHandler.cs | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Replays/OsuFramedReplayInputHandler.cs b/osu.Game.Rulesets.Osu/Replays/OsuFramedReplayInputHandler.cs index 614edba400..c6ac1dd346 100644 --- a/osu.Game.Rulesets.Osu/Replays/OsuFramedReplayInputHandler.cs +++ b/osu.Game.Rulesets.Osu/Replays/OsuFramedReplayInputHandler.cs @@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Replays { } - protected override bool IsImportant(OsuReplayFrame frame) => frame?.Actions.Any() ?? false; + protected override bool IsImportant(OsuReplayFrame frame) => frame.Actions.Any(); protected Vector2? Position { diff --git a/osu.Game/Rulesets/Replays/FramedReplayInputHandler.cs b/osu.Game/Rulesets/Replays/FramedReplayInputHandler.cs index 178e1c2364..e8c5472ba6 100644 --- a/osu.Game/Rulesets/Replays/FramedReplayInputHandler.cs +++ b/osu.Game/Rulesets/Replays/FramedReplayInputHandler.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using JetBrains.Annotations; using osu.Framework.Input.StateChanges; using osu.Game.Input.Handlers; using osu.Game.Replays; @@ -87,14 +88,24 @@ namespace osu.Game.Rulesets.Replays protected bool HasFrames => Frames.Count > 0; - private bool inImportantSection => - HasFrames && FrameAccuratePlayback && - //a button is in a pressed state - IsImportant(currentDirection > 0 ? CurrentFrame : NextFrame) && - //the next frame is within an allowable time span - Math.Abs(CurrentTime - NextFrame?.Time ?? 0) <= AllowedImportantTimeSpan; + private bool inImportantSection + { + get + { + if (!HasFrames || !FrameAccuratePlayback) + return false; - protected virtual bool IsImportant(TFrame frame) => false; + var checkFrame = currentDirection > 0 ? CurrentFrame : NextFrame; + + if (checkFrame == null) + return false; + + return IsImportant(currentDirection > 0 ? CurrentFrame : NextFrame) && //a button is in a pressed state + Math.Abs(CurrentTime - NextFrame?.Time ?? 0) <= AllowedImportantTimeSpan; //the next frame is within an allowable time span + } + } + + protected virtual bool IsImportant([NotNull] TFrame frame) => false; /// /// Update the current frame based on an incoming time value.