From 2f25f0dc0f83a7f247074a2fe8dce5a7095a8e29 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Wed, 3 Dec 2025 23:29:07 -0600 Subject: [PATCH] HAX to make it crash less --- src/cascadia/TerminalControl/ControlCore.cpp | 19 +++++++++++++------ src/cascadia/TerminalControl/ControlCore.h | 9 ++++++++- src/common.build.pre.props | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 54cc08e58b..b4fc5e5b3e 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -160,6 +160,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void ControlCore::_setupDispatcherAndCallbacks() { + ///* TODO(DH) */ return; // Get our dispatcher. If we're hosted in-proc with XAML, this will get // us the same dispatcher as TermControl::Dispatcher(). If we're out of // proc, this'll return null. We'll need to instead make a new @@ -408,12 +409,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation _terminal->Create(viewportSize, Utils::ClampToShortMax(_settings.HistorySize(), 0), *_renderer); _terminal->UpdateSettings(_settings); - // Tell the render engine to notify us when the swap chain changes. - // We do this after we initially set the swapchain so as to avoid - // unnecessary callbacks (and locking problems) - _renderEngine->SetCallback([this](HANDLE handle) { - _renderEngineSwapChainChanged(handle); - }); + if (_hookup == HookupMode::ForComposition) + { + // Tell the render engine to notify us when the swap chain changes. + // We do this after we initially set the swapchain so as to avoid + // unnecessary callbacks (and locking problems) + _renderEngine->SetCallback([this](HANDLE handle) { + _renderEngineSwapChainChanged(handle); + }); + } _renderEngine->SetRetroTerminalEffect(_settings.RetroTerminalEffect()); _renderEngine->SetPixelShaderPath(_settings.PixelShaderPath()); @@ -439,6 +443,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation const float compositionScale, const uint64_t hwnd) { + _owningHwnd = hwnd; + _hookup = HookupMode::ForHwnd; + auto i = Initialize(actualWidth, actualHeight, compositionScale); if (i) { diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index cecd084a1f..05de27db23 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -78,6 +78,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation struct ControlCore : ControlCoreT { + private: + enum class HookupMode + { + ForHwnd = 0x0, + ForComposition = 0x1, + }; public: ControlCore(Control::IControlSettings settings, Control::IControlAppearance unfocusedAppearance, @@ -382,7 +388,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // // Though, the unit tests don't actually run in TAEF's main // thread, so we don't care when we're running in tests. - assert(_inUnitTests || _dispatcher.HasThreadAccess()); + assert(_hookup == HookupMode::ForHwnd || _inUnitTests || _dispatcher.HasThreadAccess()); } #endif return _closing; @@ -427,6 +433,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation std::atomic _initializedTerminal{ false }; bool _isReadOnly{ false }; bool _closing{ false }; + HookupMode _hookup{ HookupMode::ForComposition }; struct StashedColorScheme { diff --git a/src/common.build.pre.props b/src/common.build.pre.props index b3f57bf230..e1398de048 100644 --- a/src/common.build.pre.props +++ b/src/common.build.pre.props @@ -137,7 +137,7 @@ This diagnostic is broken in VS 17.7 which our CI currently uses. It's fixed in 17.8. --> 4201;4312;4467;5105;26434;26445;26456;26478;26494;%(DisableSpecificWarnings) - _WINDOWS;EXTERNAL_BUILD;_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING;%(PreprocessorDefinitions) + _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING;_WINDOWS;EXTERNAL_BUILD;_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING;%(PreprocessorDefinitions) true precomp.h ProgramDatabase