diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 6a617d5f047..7769d964e5d 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -2306,9 +2306,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation void ControlCore::DetachUiaEngine(::Microsoft::Console::Render::UiaEngine* const pEngine) { const auto lock = _terminal->LockForWriting(); + LOG_IF_FAILED(pEngine->Disable()); _renderer->RemoveRenderEngine(pEngine); } + HRESULT ControlCore::DisableUiaEngine(::Microsoft::Console::Render::UiaEngine* const pEngine) + { + const auto lock = _terminal->LockForWriting(); + return pEngine->Disable(); + } + bool ControlCore::IsInReadOnlyMode() const { return _isReadOnly; diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index a5cad83dbc2..8a58eb57dab 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -241,6 +241,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void AttachUiaEngine(::Microsoft::Console::Render::UiaEngine* const pEngine); void DetachUiaEngine(::Microsoft::Console::Render::UiaEngine* const pEngine); + [[nodiscard]] HRESULT DisableUiaEngine(::Microsoft::Console::Render::UiaEngine* const pEngine); bool IsInReadOnlyMode() const; void ToggleReadOnlyMode(); diff --git a/src/cascadia/TerminalControl/ControlInteractivity.cpp b/src/cascadia/TerminalControl/ControlInteractivity.cpp index 71232e6037a..438ad0f02ad 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.cpp +++ b/src/cascadia/TerminalControl/ControlInteractivity.cpp @@ -76,14 +76,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation // and the UIA engine will try to dispatch to the // TermControlAutomationPeer, which (is now)/(will very soon be) gone. // - // To alleviate, make sure to disable the UIA engine and remove it, - // and ALSO disable the renderer. Core.Detach will take care of the - // TriggerTeardown (which will stop the renderer - // after all current engines are done painting). - // - // Simply disabling the UIA engine is not enough, because it's - // possible that it had already started presenting here. - LOG_IF_FAILED(_uiaEngine->Disable()); + // To alleviate, core will both disable the UIA engine and remove it, + // Core.Detach will take care of the TriggerTeardown (which will stop + // the renderer after all current engines are done painting). _core->DetachUiaEngine(_uiaEngine.get()); } _core->Detach(); @@ -198,7 +193,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation if (_uiaEngine.get()) { - THROW_IF_FAILED(_uiaEngine->Disable()); + THROW_IF_FAILED(_core->DisableUiaEngine(_uiaEngine.get())); } _core->LostFocus();