diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index ea43ddd525..539b502dd0 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 @@ namespace osu.Game.Screens.Play Debug.Assert(CurrentPlayer != null); - highPerformanceSession?.Dispose(); - highPerformanceSession = null; + endHighPerformance(); // prepare for a retry. CurrentPlayer = null; @@ -329,8 +329,7 @@ namespace osu.Game.Screens.Play BackgroundBrightnessReduction = false; Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment); - highPerformanceSession?.Dispose(); - highPerformanceSession = null; + endHighPerformance(); return base.OnExiting(e); } @@ -531,11 +530,7 @@ namespace osu.Game.Screens.Play // 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 @@ namespace osu.Game.Screens.Play scheduledPushPlayer = null; } + private void endHighPerformance() => Interlocked.Exchange(ref highPerformanceSession, null)?.Dispose(); + #region Disposal protected override void Dispose(bool isDisposing) @@ -580,8 +577,7 @@ namespace osu.Game.Screens.Play DisposalTask = LoadTask?.ContinueWith(_ => CurrentPlayer?.Dispose()); } - highPerformanceSession?.Dispose(); - highPerformanceSession = null; + endHighPerformance(); } #endregion