Skip to content

Commit

Permalink
Merge pull request #6033 from hwabis/push-screen-on-exit-fix
Browse files Browse the repository at this point in the history
Throw exception when pushing a screen at OnExiting without blocking
  • Loading branch information
peppy authored Oct 23, 2023
2 parents 90d9286 + f3a5205 commit ca14a9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvalidOperationException>(
() => screen1.Exit()));
}

[Test]
public void TestInvalidPushBlocksNonImmediateSuspend()
{
Expand Down
3 changes: 2 additions & 1 deletion osu.Framework/Screens/ScreenStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ca14a9a

Please sign in to comment.