diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs index 7474f18455..d8e75ce301 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs @@ -798,6 +798,26 @@ public void TestPushOnExiting() AddAssert("Stack is not empty", () => stack.CurrentScreen != null); } + [Test] + public void TestPushOnExitingWithoutBlocking() + { + TestScreen screen1 = null; + + pushAndEnsureCurrent(() => + { + screen1 = new TestScreen(id: 1); + screen1.Exiting = () => + { + screen1.Push(new TestScreen(id: 2)); + return false; + }; + return screen1; + }); + + AddStep("ensure push throws", () => Assert.Throws( + () => screen1.Exit())); + } + [Test] public void TestInvalidPushBlocksNonImmediateSuspend() { diff --git a/osu.Framework/Screens/ScreenStack.cs b/osu.Framework/Screens/ScreenStack.cs index a319ea0c42..865944f41a 100644 --- a/osu.Framework/Screens/ScreenStack.cs +++ b/osu.Framework/Screens/ScreenStack.cs @@ -304,7 +304,8 @@ private bool exitFrom([CanBeNull] IScreen source, bool shouldFireExitEvent = tru if ((source == null || toExit.ValidForResume) && blockRequested) return true; - stack.Pop(); + if (toExit != stack.Pop()) + throw new InvalidOperationException($"Cannot push to {nameof(ScreenStack)} during exit without blocking the exit."); } // we will probably want to change this logic when we support returning to a screen after exiting.