From 0c72f8748bfb1bb5b4982c32bf5187295472ba0a Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 28 Apr 2020 16:38:28 -0500 Subject: [PATCH] Well this is mental --- src/cascadia/WindowsTerminal/AppHost.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index adf042ba22f..6b6c312e2a8 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -166,6 +166,24 @@ void AppHost::Initialize() // set that content as well. _window->SetContent(_logic.GetRoot()); _window->OnAppInitialized(); + + // THIS IS A HACK + // + // We've got a weird crash that happens terribly inconsistently, but pretty + // readily on migrie's laptop, only in Debug mode. Apparently, there's some + // weird ref-counting magic that goes on during teardown, and our + // Application doesn't get closed quite right, which can cause us to crash + // into the debugger. This of course, only happens on exit, and happens + // somewhere in the XamlHost.dll code. + // + // Crazily, if we _manually leak the Application_ here, then the crash + // doesn't happen. This doesn't matter, because we really want the + // Application to live for _the entire lifetime of the process_, so the only + // time when this object would actually need to get cleaned up is _during + // exit_. So we can safely leak this Application object, and have it just + // get cleaned up normally when our process exits. + ::winrt::TerminalApp::App a{ _app }; + ::winrt::detach_abi(a); } // Method Description: