`Application.Init` / `Shutdown` are confused about `TopLevel`s created by `Application.Begin` and not cleaned up by `Application.End`
See original GitHub issueIn UI Catalog
, before I start a Scenario
I call Application.Shutdown
. You are supposed to book end every call to Applciation.Begin
with Shutdown
.
I just discovered that Shutdown
does not actually clean up. As a result, the next time Application.Begin
is called, fields like topLevels
still have data. This means that the ‘old’ stuff interferes with the ‘new’ stuff.
Short-term fix is to uninitialize stuff:
/// <summary>
/// Shutdown an application initalized with <see cref="Init()"/>
/// </summary>
public static void Shutdown ()
{
Driver.End ();
foreach (var t in toplevels) {
t.Running = false;
}
toplevels.Clear ();
Current = null;
CurrentView = null;
Top = null;
MainLoop = null;
_initialized = false;
}
Crux of issue (added Nov 2, 2022 via #2162):
Init/Shutdown are supposed to clean up. But in ResetState
, the loop that disposes of the topLevels
does nothing because the Toplevel
that was created by Init
has not been added to topLevels
(it gets added by Begin
).
The right fix (IMO) would be to move all that state into RunState
and leverage the fact that RunState
is already IDisposable
. However, it may not be possible to do this without a breaking change.
Issue Analytics
- State:
- Created 3 years ago
- Comments:27
Top GitHub Comments
See latest update to the PR.
I have implemented your suggested fix (with tweaks). All unit tests except
KeyBindings_Command_With_MdiTop
pass.No asserts from UI Catalog.
Check it out!!!
See if you can figure out why that test broke…
I did this and wrote more unit tests to prove it works. The new docs for these actions are: