Repository: microsoft/terminal (language: cpp)

Issue:
1.16 - Crash in SUI when hot-reloading SUI
Unsure if it's just my settings blob or not. 

1. Open a SUI tab
2. save the `settings.json` file
3. 💥

Crash is in 

<details>
<summary>stack</summary>

```
>	Microsoft.Terminal.Settings.Editor.dll!winrt::impl::consume_Microsoft_Terminal_Settings_Editor_IColorSchemeViewModel<winrt::Microsoft::Terminal::Settings::Editor::IColorSchemeViewModel>::Name() Line 688	C++
 	Microsoft.Terminal.Settings.Editor.dll!winrt::Microsoft::Terminal::Settings::Editor::implementation::ColorSchemesPageViewModel::UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings & settings) Line 37	C++
 	Microsoft.Terminal.Settings.Editor.dll!winrt::impl::produce<winrt::Microsoft::Terminal::Settings::Editor::implementation::ColorSchemesPageViewModel,winrt::Microsoft::Terminal::Settings::Editor::IColorSchemesPageViewModel>::UpdateSettings(void * settings) Line 4015	C++
 	Microsoft.Terminal.Settings.Editor.dll!winrt::impl::consume_Microsoft_Terminal_Settings_Editor_IColorSchemesPageViewModel<winrt::Microsoft::Terminal::Settings::Editor::IColorSchemesPageViewModel>::UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings & settings) Line 791	C++
 	Microsoft.Terminal.Settings.Editor.dll!winrt::Microsoft::Terminal::Settings::Editor::implementation::MainPage::UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings & settings) Line 159	C++
 	Microsoft.Terminal.Settings.Editor.dll!winrt::impl::produce<winrt::Microsoft::Terminal::Settings::Editor::implementation::MainPage,winrt::Microsoft::Terminal::Settings::Editor::IMainPage>::UpdateSettings(void * settings) Line 5371	C++
 	TerminalApp.dll!winrt::impl::consume_Microsoft_Terminal_Settings_Editor_IMainPage<winrt::Microsoft::Terminal::Settings::Editor::IMainPage>::UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings & settings) Line 1721	C++
 	TerminalApp.dll!winrt::TerminalApp::implementation::SettingsTab::UpdateSettings(winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings settings) Line 44	C++
```

</details>

`_CurrentScheme` is `nullptr`. 

\<conjecture>I bet it's cause `_CurrentScheme` doesn't get set until the first _UpdateSettings call, which doesn't happen until a settings reload. 


Discussion / hints:

Fix patch:
diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp
index fa9e1caabe5..d5c1280f437 100644
--- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp
+++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp
@@ -34,26 +34,35 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
         // we still have the same CurrentScheme as before (if that scheme still exists)
 
         // Store the name of the current scheme
-        const auto currentSchemeName = CurrentScheme().Name();
+        const auto currentSchemeName = HasCurrentScheme() ? CurrentScheme().Name() : hstring{};
 
         // Re-initialize the color scheme list
         _MakeColorSchemeVMsHelper();
 
         // Re-select the previously selected scheme if it exists
-        const auto it = _AllColorSchemes.First();
-        while (it.HasCurrent())
+        if (!currentSchemeName.empty())
         {
-            auto scheme = *it;
-            if (scheme.Name() == currentSchemeName)
+            const auto it = _AllColorSchemes.First();
+            while (it.HasCurrent())
             {
-                CurrentScheme(scheme);
-                break;
+                auto scheme = *it;
+                if (scheme.Name() == currentSchemeName)
+                {
+                    CurrentScheme(scheme);
+                    break;
+                }
+                it.MoveNext();
+            }
+            if (!it.HasCurrent())
+            {
+                // we didn't find the previously selected scheme
+                CurrentScheme(nullptr);
             }
-            it.MoveNext();
         }
-        if (!it.HasCurrent())
+        else
         {
-            // we didn't find the previously selected scheme
+            // didn't have a scheme,
+            // so skip over looking through the schemes
             CurrentScheme(nullptr);
         }
     }


Test patch: