Merge pull request #4563 from peppy/fix-frame-handler-nullrefs

Fix replay handler nullref crashes

Co-authored-by: Dan Balasescu <1329837+smoogipoo@users.noreply.github.com>
This commit is contained in:
Dean Herbert 2019-04-01 11:17:07 +09:00 committed by GitHub
commit 693ac140d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -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
{

View File

@ -278,7 +278,7 @@ namespace osu.Game.Tests.NonVisual
protected override double AllowedImportantTimeSpan => 1000;
protected override bool IsImportant(TestReplayFrame frame) => frame?.IsImportant ?? false;
protected override bool IsImportant(TestReplayFrame frame) => frame.IsImportant;
}
}
}

View File

@ -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 frame = currentDirection > 0 ? CurrentFrame : NextFrame;
if (frame == null)
return false;
return IsImportant(frame) && //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;
/// <summary>
/// Update the current frame based on an incoming time value.