From a0eaea84f0200ad6cc899e231b8086cdf2fc6dbb Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 18 Aug 2022 19:16:15 -0500 Subject: [PATCH] Fix a crash on exit with the command palette open (#13778) Fixes MSFT:38775539 Might also fix MSFT:38614563 Looking at this code should be pretty clear what's going on. On exit, the XAML root is already nulled out. But here, we're just yolo'ing and assuming it exists (why wouldn't it). So yea. This is like weirdly high percent of crashes internally, but that's not from real users. Real users, I suspect hit this as like .3% of our crashes. Not zero, but _low_. * [x] tested manually
May also be related to... * MSFT:40602905 * MSFT:40602904 * MSFT:40412800 * MSFT:35213459 <---has links (cherry picked from commit 64bcc0bd25fd2543f4a71dfc5beb1063b807851b) Service-Card-Id: 85486788 Service-Version: 1.15 --- src/cascadia/TerminalApp/CommandPalette.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index 1bc72516d66..6aa2be583a2 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -474,7 +474,13 @@ namespace winrt::TerminalApp::implementation return; } - auto focusedElementOrAncestor = Input::FocusManager::GetFocusedElement(this->XamlRoot()).try_as(); + auto root = this->XamlRoot(); + if (!root) + { + return; + } + + auto focusedElementOrAncestor = Input::FocusManager::GetFocusedElement(root).try_as(); while (focusedElementOrAncestor) { if (focusedElementOrAncestor == *this)