Repository: microsoft/terminal (language: cpp)

Issue:
Crash on launch with a snippets pane, and multiple windows(?)
This one's weird, cause it never happened in dev build test. Maybe it's only in Release builds? Maybe only with that exact pane layout? I only hit it on a canary build without symbols, hmmmm


Discussion / hints:

Fix patch:
diff --git a/src/cascadia/TerminalApp/CommandPalette.cpp b/src/cascadia/TerminalApp/CommandPalette.cpp
index b54ee9a5c6f..4817cd52424 100644
--- a/src/cascadia/TerminalApp/CommandPalette.cpp
+++ b/src/cascadia/TerminalApp/CommandPalette.cpp
@@ -1204,8 +1204,6 @@ namespace winrt::TerminalApp::implementation
     {
         Visibility(Visibility::Collapsed);
 
-        PreviewAction.raise(*this, nullptr);
-
         // Reset visibility in case anchor mode tab switcher just finished.
         _searchBox().Visibility(Visibility::Visible);
 
@@ -1216,6 +1214,7 @@ namespace winrt::TerminalApp::implementation
 
         ParentCommandName(L"");
         _currentNestedCommands.Clear();
+        PreviewAction.raise(*this, nullptr);
     }
 
     void CommandPalette::EnableTabSwitcherMode(const uint32_t startIdx, TabSwitcherMode tabSwitcherMode)
diff --git a/src/cascadia/TerminalApp/SnippetsPaneContent.cpp b/src/cascadia/TerminalApp/SnippetsPaneContent.cpp
index b6415c6ba79..3df8c17e11f 100644
--- a/src/cascadia/TerminalApp/SnippetsPaneContent.cpp
+++ b/src/cascadia/TerminalApp/SnippetsPaneContent.cpp
@@ -21,7 +21,8 @@ namespace winrt
 
 namespace winrt::TerminalApp::implementation
 {
-    SnippetsPaneContent::SnippetsPaneContent()
+    SnippetsPaneContent::SnippetsPaneContent() :
+        _allTasks{ winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>() }
     {
         InitializeComponent();
 
@@ -54,7 +55,7 @@ namespace winrt::TerminalApp::implementation
         const auto tasks = co_await _settings.GlobalSettings().ActionMap().FilterToSnippets(winrt::hstring{}, winrt::hstring{}); // IVector<Model::Command>
         co_await wil::resume_foreground(Dispatcher());
 
-        _allTasks = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
+        _allTasks.Clear();
         for (const auto& t : tasks)
         {
             const auto& filtered{ winrt::make<FilteredTask>(t) };
diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp
index b7e343998d6..3dbac435794 100644
--- a/src/cascadia/TerminalCore/Terminal.cpp
+++ b/src/cascadia/TerminalCore/Terminal.cpp
@@ -1615,6 +1615,12 @@ void Terminal::PreviewText(std::wstring_view input)
     static constexpr TextAttribute previewAttrs{ CharacterAttributes::Italics, TextColor{}, TextColor{}, 0u, TextColor{} };
 
     auto lock = LockForWriting();
+
+    if (_mainBuffer == nullptr)
+    {
+        return;
+    }
+
     if (input.empty())
     {
         snippetPreview.text = L"";


Test patch: