Centralise TrackManager.AddItem logic to avoid duplicate adds

This commit is contained in:
Dean Herbert
2017-07-20 17:46:23 +09:00
parent 67b95926c4
commit 3bdd4d7d02
5 changed files with 17 additions and 28 deletions

View File

@ -135,10 +135,17 @@ namespace osu.Game
Beatmap.ValueChanged += b =>
{
// this disposal is done to stop the audio track.
// it may not be exactly what we want for cases beatmaps are reused, as it will
// trigger a fresh load of contained resources.
lastBeatmap?.Dispose();
// compare to last baetmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
if (lastBeatmap?.Track != b.Track)
{
// this disposal is done to stop the audio track.
// it may not be exactly what we want for cases beatmaps are reused, as it will
// trigger a fresh load of contained resources.
lastBeatmap?.Dispose();
Audio.Track.AddItem(b.Track);
}
lastBeatmap = b;
};