diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index ea43ddd525d1..539b502dd034 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Threading; using System.Threading.Tasks; using ManagedBass.Fx; using osu.Framework.Allocation; @@ -288,8 +289,7 @@ public override void OnResuming(ScreenTransitionEvent e) Debug.Assert(CurrentPlayer != null); - highPerformanceSession?.Dispose(); - highPerformanceSession = null; + endHighPerformance(); // prepare for a retry. CurrentPlayer = null; @@ -329,8 +329,7 @@ public override bool OnExiting(ScreenExitEvent e) BackgroundBrightnessReduction = false; Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment); - highPerformanceSession?.Dispose(); - highPerformanceSession = null; + endHighPerformance(); return base.OnExiting(e); } @@ -531,11 +530,7 @@ private void pushWhenLoaded() // ensure that once we have reached this "point of no return", readyForPush will be false for all future checks (until a new player instance is prepared). Player consumedPlayer = consumePlayer(); - consumedPlayer.OnShowingResults += () => - { - highPerformanceSession?.Dispose(); - highPerformanceSession = null; - }; + consumedPlayer.OnShowingResults += endHighPerformance; ContentOut(); @@ -568,6 +563,8 @@ private void cancelLoad() scheduledPushPlayer = null; } + private void endHighPerformance() => Interlocked.Exchange(ref highPerformanceSession, null)?.Dispose(); + #region Disposal protected override void Dispose(bool isDisposing) @@ -580,8 +577,7 @@ protected override void Dispose(bool isDisposing) DisposalTask = LoadTask?.ContinueWith(_ => CurrentPlayer?.Dispose()); } - highPerformanceSession?.Dispose(); - highPerformanceSession = null; + endHighPerformance(); } #endregion