From 5b9d906ad510137956e6e29c69e5fa2d976714a6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 12 Sep 2017 16:55:48 +0900 Subject: [PATCH] Improve beatmap track disposal logic - [ ] Depends on https://github.com/ppy/osu-framework/pull/1035 --- osu.Game/Beatmaps/WorkingBeatmap.cs | 11 +++++++++-- osu.Game/OsuGameBase.cs | 13 +++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index e6a26baa66..df8e7f5e3b 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -109,10 +109,17 @@ public void TransferTo(WorkingBeatmap other) public virtual void Dispose() { - track?.Dispose(); - track = null; background?.Dispose(); background = null; } + + public void DisposeTrack() + { + lock (trackLock) + { + track?.Dispose(); + track = null; + } + } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 76eb7d5101..d81c7cdf73 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -152,10 +152,19 @@ private void load() Beatmap.ValueChanged += b => { + var trackLoaded = lastBeatmap?.TrackLoaded ?? false; + // compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo) - if (lastBeatmap?.Track != b.Track) + if (!trackLoaded || lastBeatmap?.Track != b.Track) { - lastBeatmap?.Track?.Dispose(); + if (trackLoaded) + { + Debug.Assert(lastBeatmap != null); + Debug.Assert(lastBeatmap.Track != null); + + lastBeatmap.DisposeTrack(); + } + Audio.Track.AddItem(b.Track); }