Merge pull request #16238 from peppy/fix-incorrect-delegate-capture

Fix incorrect delegate capture leading to slow leak of audio tracks
This commit is contained in:
Dan Balasescu
2021-12-24 21:34:04 +09:00
committed by GitHub

View File

@ -342,11 +342,9 @@ namespace osu.Game.Overlays
private void changeTrack()
{
var queuedTrack = getQueuedTrack();
var lastTrack = CurrentTrack;
var queuedTrack = new DrawableTrack(current.LoadTrack());
queuedTrack.Completed += () => onTrackCompleted(current);
CurrentTrack = queuedTrack;
// At this point we may potentially be in an async context from tests. This is extremely dangerous but we have to make do for now.
@ -370,6 +368,15 @@ namespace osu.Game.Overlays
});
}
private DrawableTrack getQueuedTrack()
{
// Important to keep this in its own method to avoid inadvertently capturing unnecessary variables in the callback.
// Can lead to leaks.
var queuedTrack = new DrawableTrack(current.LoadTrack());
queuedTrack.Completed += () => onTrackCompleted(current);
return queuedTrack;
}
private void onTrackCompleted(WorkingBeatmap workingBeatmap)
{
// the source of track completion is the audio thread, so the beatmap may have changed before firing.