1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:12:54 +08:00

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
commit d36fe3af09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.