From 7efb4ce30a0d50a16503ce0a75d24db5a961be75 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Jul 2024 18:36:40 +0900 Subject: [PATCH] Fix multiple disposals resulting in assert being hit --- osu.Game.Tests/Visual/Menus/TestAudioDucking.cs | 10 ++++++++++ osu.Game/Overlays/MusicController.cs | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Menus/TestAudioDucking.cs b/osu.Game.Tests/Visual/Menus/TestAudioDucking.cs index 1639912d29..e704fc0e83 100644 --- a/osu.Game.Tests/Visual/Menus/TestAudioDucking.cs +++ b/osu.Game.Tests/Visual/Menus/TestAudioDucking.cs @@ -101,6 +101,16 @@ namespace osu.Game.Tests.Visual.Menus AddUntilStep("wait for restore to complete", () => Game.Audio.Tracks.AggregateVolume.Value, () => Is.EqualTo(normalVolume).Within(float.Epsilon)); } + [Test] + public void TestMultipleDisposalIsNoop() + { + IDisposable duckOp1 = null!; + + AddStep("duck", () => duckOp1 = Game.MusicController.Duck()); + AddStep("restore", () => duckOp1.Dispose()); + AddStep("restore", () => duckOp1.Dispose()); + } + [Test] public void TestMultipleDucksDifferentPieces() { diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 637fcb57e2..8fa77b6153 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -284,8 +283,8 @@ namespace osu.Game.Overlays void restoreDucking() => Schedule(() => { - Debug.Assert(duckOperations.Contains(parameters)); - duckOperations.Remove(parameters); + if (!duckOperations.Remove(parameters)) + return; DuckParameters? restoreVolumeOperation = duckOperations.MinBy(p => p.DuckVolumeTo); DuckParameters? restoreLowPassOperation = duckOperations.MinBy(p => p.DuckCutoffTo);