Skip to content

Commit

Permalink
Centralise calls to end high performance sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Sep 9, 2024
1 parent b01fb2a commit 57fe5bd
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using ManagedBass.Fx;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -580,8 +577,7 @@ protected override void Dispose(bool isDisposing)
DisposalTask = LoadTask?.ContinueWith(_ => CurrentPlayer?.Dispose());
}

highPerformanceSession?.Dispose();
highPerformanceSession = null;
endHighPerformance();
}

#endregion
Expand Down

0 comments on commit 57fe5bd

Please sign in to comment.