From 4ad3156f42d9656adb9ff481334e0eb547a5244a Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Fri, 29 Oct 2021 07:09:41 -0700 Subject: [PATCH] Check that the control exists before we try to focus it (#11635) ## Summary of the Pull Request When we are on a settings UI tab, `_GetActiveControl` returns a `nullptr`, make sure not to try and focus it in that case ## PR Checklist * [x] Closes #11633 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [x] I work here ## Validation Steps Performed No longer crashes (cherry picked from commit a7ce93a35721e2743e1c03a4c9b18c8c20f4306f) --- src/cascadia/TerminalApp/TerminalPage.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index e95810aaba6..2dcb5d36c2c 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1723,7 +1723,10 @@ namespace winrt::TerminalApp::implementation // the control here instead. if (_startupState == StartupState::Initialized) { - _GetActiveControl().Focus(FocusState::Programmatic); + if (const auto control = _GetActiveControl()) + { + control.Focus(FocusState::Programmatic); + } } } CATCH_LOG();