From 802b996ed1ffa9133cfe9a40fd684e5cabaac7e2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 25 Mar 2024 15:30:13 +0000 Subject: [PATCH] Ensures _latestClosedRunStateToplevel is cleanup on ResetState and support OverlappedTop. --- 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 e98b06d18..718bb3868 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -101,9 +101,16 @@ public static partial class Application if (Top is { }) { Debug.Assert (Top.WasDisposed); + // If End wasn't called _latestClosedRunStateToplevel may be null + if (_latestClosedRunStateToplevel is { }) + { + Debug.Assert (_latestClosedRunStateToplevel.WasDisposed); + Debug.Assert (_latestClosedRunStateToplevel == Top); + } } #endif Top = null; + _latestClosedRunStateToplevel = null; // MainLoop stuff MainLoop?.Dispose (); @@ -1064,7 +1071,14 @@ public static partial class Application // Don't dispose runState.Toplevel. It's up to caller dispose it // If it's not the same as the current in the RunIteration, // it will be fixed later in the next RunIteration. - _latestClosedRunStateToplevel = runState.Toplevel; + if (OverlappedTop is { } && !_topLevels.Contains (OverlappedTop)) + { + _latestClosedRunStateToplevel = OverlappedTop; + } + else + { + _latestClosedRunStateToplevel = runState.Toplevel; + } runState.Toplevel = null; runState.Dispose (); }