Improve beatmap track disposal logic

- [ ] Depends on https://github.com/ppy/osu-framework/pull/1035
This commit is contained in:
Dean Herbert 2017-09-12 16:55:48 +09:00
parent 2f1af3812d
commit 5b9d906ad5
2 changed files with 20 additions and 4 deletions

View File

@ -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;
}
}
}
}

View File

@ -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);
}