Fix samples not being disposed

This commit is contained in:
smoogipoo
2020-11-12 18:48:25 +09:00
parent e44a8b3934
commit 261ddd2b4a

View File

@ -10,6 +10,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Threading; using osu.Framework.Threading;
@ -126,6 +127,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
[CanBeNull] [CanBeNull]
private HitObjectLifetimeEntry lifetimeEntry; private HitObjectLifetimeEntry lifetimeEntry;
private Container<PausableSkinnableSound> samplesContainer;
/// <summary> /// <summary>
/// Creates a new <see cref="DrawableHitObject"/>. /// Creates a new <see cref="DrawableHitObject"/>.
/// </summary> /// </summary>
@ -142,6 +145,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {
config.BindWith(OsuSetting.PositionalHitSounds, userPositionalHitSounds); config.BindWith(OsuSetting.PositionalHitSounds, userPositionalHitSounds);
// Explicit non-virtual function call.
base.AddInternal(samplesContainer = new Container<PausableSkinnableSound> { RelativeSizeAxes = Axes.Both });
} }
protected override void LoadAsyncComplete() protected override void LoadAsyncComplete()
@ -296,11 +302,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
protected virtual void LoadSamples() protected virtual void LoadSamples()
{ {
if (Samples != null) samplesContainer.Clear();
{ Samples = null;
RemoveInternal(Samples);
Samples = null;
}
var samples = GetSamples().ToArray(); var samples = GetSamples().ToArray();
@ -313,8 +316,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}."); + $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
} }
Samples = new PausableSkinnableSound(samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s))); samplesContainer.Add(Samples = new PausableSkinnableSound(samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s))));
AddInternal(Samples);
} }
private void onSamplesChanged(object sender, NotifyCollectionChangedEventArgs e) => LoadSamples(); private void onSamplesChanged(object sender, NotifyCollectionChangedEventArgs e) => LoadSamples();