1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 16:47:24 +08:00

Prevent KeysPerSecondCounter from NRE when no instance is initialized

This commit is contained in:
Ryuki 2022-08-05 16:31:20 +02:00
parent 0c07df2c26
commit 0886137e39
No known key found for this signature in database
GPG Key ID: A353889EAEACBF49
2 changed files with 5 additions and 5 deletions

View File

@ -18,7 +18,7 @@ namespace osu.Game.Screens.Play.HUD.KPSCounter
public static void AddInput()
{
instance?.onNewInput.Invoke();
instance?.onNewInput?.Invoke();
}
public static KeysPerSecondCalculator GetInstance(GameplayClock gameplayClock = null, DrawableRuleset drawableRuleset = null)
@ -41,9 +41,9 @@ namespace osu.Game.Screens.Play.HUD.KPSCounter
private event Action onNewInput;
private IClock workingClock => (IClock)drawableRuleset.FrameStableClock ?? gameplayClock;
private IClock workingClock => (IClock)drawableRuleset?.FrameStableClock ?? gameplayClock;
// Having the rate from mods is preffered to using GameplayClock.TrueGameplayRate()
// Having the rate from mods is preferred to using GameplayClock.TrueGameplayRate()
// as it returns 0 when paused in replays, not useful for players who want to "analyze" a replay.
private double rate => (drawableRuleset.Mods.FirstOrDefault(m => m is ModRateAdjust) as ModRateAdjust)?.SpeedChange.Value
?? 1;
@ -64,7 +64,7 @@ namespace osu.Game.Screens.Play.HUD.KPSCounter
private void addTimestamp()
{
if (workingClock != null && workingClock.CurrentTime >= maxTime && gameplayClock.TrueGameplayRate > 0)
if (Ready && workingClock.CurrentTime >= maxTime && gameplayClock.TrueGameplayRate > 0)
{
timestamps.Add(workingClock.CurrentTime);
maxTime = workingClock.CurrentTime;

View File

@ -1046,7 +1046,7 @@ namespace osu.Game.Screens.Play
fadeOut();
KeysPerSecondCalculator.GetInstance().Dispose();
KeysPerSecondCalculator.GetInstance()?.Dispose();
return base.OnExiting(e);
}