mirror of
https://github.com/ppy/osu
synced 2025-03-25 04:18:03 +00:00
Merge pull request #6344 from smoogipoo/fix-track-leak
Fix memory leaks due to audio track recycle order
This commit is contained in:
commit
8d6a177a6b
@ -1,42 +0,0 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
|
||||||
|
|
||||||
using System.Diagnostics;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A <see cref="Bindable{T}"/> for the <see cref="OsuGame"/> beatmap.
|
|
||||||
/// This should be used sparingly in-favour of <see cref="IBindable{WorkingBeatmap}"/>.
|
|
||||||
/// </summary>
|
|
||||||
public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap>
|
|
||||||
{
|
|
||||||
private WorkingBeatmap lastBeatmap;
|
|
||||||
|
|
||||||
protected BindableBeatmap(WorkingBeatmap defaultValue)
|
|
||||||
: base(defaultValue)
|
|
||||||
{
|
|
||||||
BindValueChanged(b => updateAudioTrack(b.NewValue), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateAudioTrack(WorkingBeatmap beatmap)
|
|
||||||
{
|
|
||||||
var trackLoaded = lastBeatmap?.TrackLoaded ?? false;
|
|
||||||
|
|
||||||
// compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
|
|
||||||
if (!trackLoaded || lastBeatmap?.Track != beatmap.Track)
|
|
||||||
{
|
|
||||||
if (trackLoaded)
|
|
||||||
{
|
|
||||||
Debug.Assert(lastBeatmap != null);
|
|
||||||
Debug.Assert(lastBeatmap.Track != null);
|
|
||||||
|
|
||||||
lastBeatmap.RecycleTrack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastBeatmap = beatmap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -202,7 +202,13 @@ namespace osu.Game
|
|||||||
// this adds a global reduction of track volume for the time being.
|
// this adds a global reduction of track volume for the time being.
|
||||||
Audio.Tracks.AddAdjustment(AdjustableProperty.Volume, new BindableDouble(0.8));
|
Audio.Tracks.AddAdjustment(AdjustableProperty.Volume, new BindableDouble(0.8));
|
||||||
|
|
||||||
beatmap = new OsuBindableBeatmap(defaultBeatmap);
|
beatmap = new NonNullableBindable<WorkingBeatmap>(defaultBeatmap);
|
||||||
|
beatmap.BindValueChanged(b => ScheduleAfterChildren(() =>
|
||||||
|
{
|
||||||
|
// compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
|
||||||
|
if (b.OldValue?.TrackLoaded == true && b.OldValue?.Track != b.NewValue?.Track)
|
||||||
|
b.OldValue.RecycleTrack();
|
||||||
|
}));
|
||||||
|
|
||||||
dependencies.CacheAs<IBindable<WorkingBeatmap>>(beatmap);
|
dependencies.CacheAs<IBindable<WorkingBeatmap>>(beatmap);
|
||||||
dependencies.CacheAs(beatmap);
|
dependencies.CacheAs(beatmap);
|
||||||
@ -292,14 +298,6 @@ namespace osu.Game
|
|||||||
|
|
||||||
public string[] HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions).ToArray();
|
public string[] HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions).ToArray();
|
||||||
|
|
||||||
private class OsuBindableBeatmap : BindableBeatmap
|
|
||||||
{
|
|
||||||
public OsuBindableBeatmap(WorkingBeatmap defaultValue)
|
|
||||||
: base(defaultValue)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OsuUserInputManager : UserInputManager
|
private class OsuUserInputManager : UserInputManager
|
||||||
{
|
{
|
||||||
protected override MouseButtonEventManager CreateButtonManagerFor(MouseButton button)
|
protected override MouseButtonEventManager CreateButtonManagerFor(MouseButton button)
|
||||||
|
@ -28,9 +28,9 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
[Cached(typeof(Bindable<WorkingBeatmap>))]
|
[Cached(typeof(Bindable<WorkingBeatmap>))]
|
||||||
[Cached(typeof(IBindable<WorkingBeatmap>))]
|
[Cached(typeof(IBindable<WorkingBeatmap>))]
|
||||||
private OsuTestBeatmap beatmap;
|
private NonNullableBindable<WorkingBeatmap> beatmap;
|
||||||
|
|
||||||
protected BindableBeatmap Beatmap => beatmap;
|
protected Bindable<WorkingBeatmap> Beatmap => beatmap;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
[Cached(typeof(IBindable<RulesetInfo>))]
|
[Cached(typeof(IBindable<RulesetInfo>))]
|
||||||
@ -73,10 +73,13 @@ namespace osu.Game.Tests.Visual
|
|||||||
// This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures
|
// This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures
|
||||||
var working = new DummyWorkingBeatmap(parent.Get<AudioManager>(), parent.Get<TextureStore>());
|
var working = new DummyWorkingBeatmap(parent.Get<AudioManager>(), parent.Get<TextureStore>());
|
||||||
|
|
||||||
beatmap = new OsuTestBeatmap(working)
|
beatmap = new NonNullableBindable<WorkingBeatmap>(working) { Default = working };
|
||||||
|
beatmap.BindValueChanged(b => ScheduleAfterChildren(() =>
|
||||||
{
|
{
|
||||||
Default = working
|
// compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
|
||||||
};
|
if (b.OldValue?.TrackLoaded == true && b.OldValue?.Track != b.NewValue?.Track)
|
||||||
|
b.OldValue.RecycleTrack();
|
||||||
|
}));
|
||||||
|
|
||||||
Dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
Dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
@ -317,13 +320,5 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
public void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);
|
public void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class OsuTestBeatmap : BindableBeatmap
|
|
||||||
{
|
|
||||||
public OsuTestBeatmap(WorkingBeatmap defaultValue)
|
|
||||||
: base(defaultValue)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user