From adbe4a0d0c816f79f77b3e22d0c6f7e370df9500 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 25 Apr 2023 23:32:44 +0200 Subject: [PATCH] Fix missing call to UpdateViewport::UpdateViewport during tearout (#15175) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This bug causes AtlasEngine to render buffer contents with an incorrect `cellCount`, which may either cause it to draw the contents only partially, or potentially access the TextBuffer contents out of bounds. `EnablePainting` sets the `_viewport` to the current viewport for some unfortunate (and quite buggy/incorrect) caching purposes, which causes `_CheckViewportAndScroll()` to think that the viewport hasn't changed in the new window. We can ensure `_CheckViewportAndScroll()` works by also setting `_forceUpdateViewport` to `true`. Part of #14957 ## PR Checklist * Tear out a tab from a smaller window to a larger window * Renderer contents adept to the larger window size ✅ --------- Co-authored-by: Mike Griese Co-authored-by: Dustin L. Howett --- src/cascadia/TerminalControl/ControlCore.cpp | 4 ++-- src/renderer/base/renderer.cpp | 1 + src/renderer/base/renderer.hpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index e2fe9c3b318..b2777ed580e 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -251,8 +251,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Bubble this up, so our new control knows how big we want the font. _FontSizeChangedHandlers(actualNewSize.width, actualNewSize.height, true); - // Turn the rendering back on now that we're ready to go. - _renderer->EnablePainting(); + // The renderer will be re-enabled in Initialize + _AttachedHandlers(*this, nullptr); } diff --git a/src/renderer/base/renderer.cpp b/src/renderer/base/renderer.cpp index fe2bbded353..c23bd85bbfa 100644 --- a/src/renderer/base/renderer.cpp +++ b/src/renderer/base/renderer.cpp @@ -638,6 +638,7 @@ void Renderer::EnablePainting() // When the renderer is constructed, the initial viewport won't be available yet, // but once EnablePainting is called it should be safe to retrieve. _viewport = _pData->GetViewport(); + _forceUpdateViewport = true; // When running the unit tests, we may be using a render without a render thread. if (_pThread) diff --git a/src/renderer/base/renderer.hpp b/src/renderer/base/renderer.hpp index 3a10a255aff..ae3ed2cfda9 100644 --- a/src/renderer/base/renderer.hpp +++ b/src/renderer/base/renderer.hpp @@ -131,7 +131,7 @@ namespace Microsoft::Console::Render std::function _pfnFrameColorChanged; std::function _pfnRendererEnteredErrorState; bool _destructing = false; - bool _forceUpdateViewport = true; + bool _forceUpdateViewport = false; #ifdef UNIT_TESTING friend class ConptyOutputTests;