Browse Source

Ensures disposing toplevel before throwing.

BDisp 1 year ago
parent
commit
97a0595353
2 changed files with 3 additions and 2 deletions
  1. 3 0
      Terminal.Gui/Application.cs
  2. 0 2
      UnitTests/Application/ApplicationTests.cs

+ 3 - 0
Terminal.Gui/Application.cs

@@ -658,6 +658,9 @@ public static partial class Application
         {
             if (Driver is null)
             {
+                // Ensure disposing the toplevel before throwing
+                top.Dispose ();
+
                 // This code path should be impossible because Init(null, null) will select the platform default driver
                 throw new InvalidOperationException (
                                                      "Init() completed without a driver being set (this should be impossible); Run<T>() cannot be called."

+ 0 - 2
UnitTests/Application/ApplicationTests.cs

@@ -618,8 +618,6 @@ public class ApplicationTests
 
         Application.Driver = null;
 
-        Application.Iteration += (s, a) => { Application.RequestStop (); };
-
         // Init has been called, but Driver has been set to null. Bad.
         Assert.Throws<InvalidOperationException> (() => Application.Run<TestToplevel> ());