diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs b/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs index bee9e3b6f1..2374b7edce 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs @@ -41,7 +41,16 @@ public void TestDoesNotRestart() AddStep("play channel 1 sample", () => channel = sample.Play()); AddUntilStep("wait for channel 1 to end", () => !channel.Playing); - AddStep("play channel 1 again", () => channel.Play()); + AddStep("play channel 1 again", () => + { + try + { + channel.Play(); + } + catch (ObjectDisposedException) + { + } + }); int audioFrames = 0; AddStep("begin tracking audio frames", () => @@ -61,6 +70,32 @@ public void TestDoesNotRestart() AddAssert("channel 1 not playing", () => !channel.Playing); } + [Test] + public void TestChannelLifetime() + { + SampleChannel channel = null; + + AddStep("play channel 1 sample", () => channel = sample.Play()); + AddUntilStep("wait for channel 1 to end", () => !channel.Playing); + + int audioFrames = 0; + AddStep("begin tracking audio frames", () => + { + audioFrames = 0; + + ScheduledDelegate del = null; + del = host.AudioThread.Scheduler.AddDelayed(() => + { + // ReSharper disable once AccessToModifiedClosure + if (++audioFrames >= 2) + del?.Cancel(); + }, 0, true); + }); + + AddUntilStep("wait for two audio frames", () => audioFrames >= 2); + AddAssert("channel 1 disposed", () => channel.IsDisposed); + } + [Test] public void TestPlayLoopingSample() {