Browse Source

Prevents run iteration if toplevel's stack is empty.

BDisp 1 year ago
parent
commit
c8b3e15028
1 changed files with 15 additions and 1 deletions
  1. 15 1
      Terminal.Gui/Application.cs

+ 15 - 1
Terminal.Gui/Application.cs

@@ -664,6 +664,15 @@ public static partial class Application
             // by using NotifyStopRunState event.
             // by using NotifyStopRunState event.
             RunLoop (runState);
             RunLoop (runState);
 
 
+            if (runState.Toplevel is null)
+            {
+#if DEBUG_IDISPOSABLE
+                Debug.Assert (_topLevels.Count == 0);
+#endif
+                runState.Dispose ();
+                return;
+            }
+
             if (!EndAfterFirstIteration)
             if (!EndAfterFirstIteration)
             {
             {
                 End (runState);
                 End (runState);
@@ -802,7 +811,7 @@ public static partial class Application
 
 
         var firstIteration = true;
         var firstIteration = true;
 
 
-        for (state.Toplevel.Running = true; state.Toplevel.Running;)
+        for (state.Toplevel.Running = true; state.Toplevel?.Running == true;)
         {
         {
             MainLoop.Running = true;
             MainLoop.Running = true;
 
 
@@ -853,6 +862,11 @@ public static partial class Application
 
 
         firstIteration = false;
         firstIteration = false;
 
 
+        if (Current == null)
+        {
+            return;
+        }
+
         if (state.Toplevel != Top && (Top.NeedsDisplay || Top.SubViewNeedsDisplay || Top.LayoutNeeded))
         if (state.Toplevel != Top && (Top.NeedsDisplay || Top.SubViewNeedsDisplay || Top.LayoutNeeded))
         {
         {
             state.Toplevel.SetNeedsDisplay (state.Toplevel.Frame);
             state.Toplevel.SetNeedsDisplay (state.Toplevel.Frame);