Fix a crash during settings update (#17751)

* Adds a check whether the thread dispatcher is already null.
  (See code comments.)
* Moves the `_settings` to only happen on the UI thread.
  Anything else wouldn't be thread safe.

Closes #17620

## Validation Steps Performed
Not reproducible. 🚫
This commit is contained in:
Leonard Hecker
2024-08-20 20:21:21 +02:00
committed by GitHub
parent 60ac45c239
commit e0dae59f38

View File

@@ -767,13 +767,22 @@ namespace winrt::TerminalApp::implementation
// definitely not on OUR UI thread.
winrt::fire_and_forget TerminalWindow::UpdateSettings(winrt::TerminalApp::SettingsLoadEventArgs args)
{
_settings = args.NewSettings();
// GH#17620: We have a bug somewhere where a window doesn't get unregistered from the window list.
// This causes UpdateSettings calls where the thread dispatcher is already null.
const auto dispatcher = _root->Dispatcher();
if (!dispatcher)
{
co_return;
}
const auto weakThis{ get_weak() };
co_await wil::resume_foreground(_root->Dispatcher());
co_await wil::resume_foreground(dispatcher);
// Back on our UI thread...
if (auto logic{ weakThis.get() })
{
_settings = args.NewSettings();
// Update the settings in TerminalPage
// We're on our UI thread right now, so this is safe
_root->SetSettings(_settings, true);