From 08ae2ef64ccffa9be1743cbe24b776a5e610d786 Mon Sep 17 00:00:00 2001 From: hwsmm <9151706+hwsmm@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:43:33 +0900 Subject: [PATCH] Dispose SampleChannel if it is not disposed yet --- osu.Framework/Audio/Sample/Sample.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/osu.Framework/Audio/Sample/Sample.cs b/osu.Framework/Audio/Sample/Sample.cs index 54bd3f1174f..1f536aa436a 100644 --- a/osu.Framework/Audio/Sample/Sample.cs +++ b/osu.Framework/Audio/Sample/Sample.cs @@ -53,5 +53,18 @@ private void onPlay(SampleChannel channel) /// /// The for the playback. protected abstract SampleChannel CreateChannel(); + + // SampleChannel IsAlive can be false if Playing is not true, even if it is not disposed yet. + // Mixer removes the channel from itself after playing to the end, so if we don't dispose this item here, it's forever lost. + protected override void ItemRemoved(SampleChannel item) + { + base.ItemRemoved(item); + + if (!item.IsDisposed) + { + item.Dispose(); + item.Update(); + } + } } }