From e4af3495c83ae47a594f4ca79c69ec7050b33f76 Mon Sep 17 00:00:00 2001 From: hwsmm <9151706+hwsmm@users.noreply.github.com> Date: Sat, 30 Nov 2024 00:26:49 +0900 Subject: [PATCH] Handle disposal in TestDoesNotRestart and add TestChannelLifetime --- .../Visual/Audio/TestSceneSampleChannels.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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() {