From c8b3e150282abc051c6f52b187f88657bdacd0bb Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 25 Mar 2024 21:56:37 +0000 Subject: [PATCH] Prevents run iteration if toplevel's stack is empty. --- Terminal.Gui/Application.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index caae6f2ba..825ba8e84 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -664,6 +664,15 @@ public static partial class Application // by using NotifyStopRunState event. RunLoop (runState); + if (runState.Toplevel is null) + { +#if DEBUG_IDISPOSABLE + Debug.Assert (_topLevels.Count == 0); +#endif + runState.Dispose (); + return; + } + if (!EndAfterFirstIteration) { End (runState); @@ -802,7 +811,7 @@ public static partial class Application var firstIteration = true; - for (state.Toplevel.Running = true; state.Toplevel.Running;) + for (state.Toplevel.Running = true; state.Toplevel?.Running == true;) { MainLoop.Running = true; @@ -853,6 +862,11 @@ public static partial class Application firstIteration = false; + if (Current == null) + { + return; + } + if (state.Toplevel != Top && (Top.NeedsDisplay || Top.SubViewNeedsDisplay || Top.LayoutNeeded)) { state.Toplevel.SetNeedsDisplay (state.Toplevel.Frame);