Skip to content

Commit

Permalink
Dispose SampleChannel if it is not disposed yet
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Oct 25, 2024
1 parent ec07a21 commit 08ae2ef
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions osu.Framework/Audio/Sample/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,18 @@ private void onPlay(SampleChannel channel)
/// </summary>
/// <returns>The <see cref="SampleChannel"/> for the playback.</returns>
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();
}
}
}
}

0 comments on commit 08ae2ef

Please sign in to comment.