From 41ee87235c2b728977c88197c2a02c4715fcde28 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 18 Aug 2022 15:12:15 -0500 Subject: [PATCH 1/2] Fix a crash on exit, with the command palette open 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 --- 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 1b2089b642d..a7061cce8bf 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 == nullptr) + { + return; + } + + auto focusedElementOrAncestor = Input::FocusManager::GetFocusedElement(root).try_as(); while (focusedElementOrAncestor) { if (focusedElementOrAncestor == *this) From a1c7e9755103a3c69d08daa104744df08c3eb428 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Thu, 18 Aug 2022 18:42:03 -0500 Subject: [PATCH 2/2] Update src/cascadia/TerminalApp/CommandPalette.cpp --- src/cascadia/TerminalApp/CommandPalette.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp index a7061cce8bf..8ebb5eefc30 100644 --- a/src/cascadia/TerminalApp/CommandPalette.cpp +++ b/src/cascadia/TerminalApp/CommandPalette.cpp @@ -475,7 +475,7 @@ namespace winrt::TerminalApp::implementation } auto root = this->XamlRoot(); - if (root == nullptr) + if (!root) { return; }