Skip to content

Commit

Permalink
Fix missing call to UpdateViewport::UpdateViewport during tearout (#1…
Browse files Browse the repository at this point in the history
…5175)

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 <migrie@microsoft.com>
Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
  • Loading branch information
3 people authored Apr 25, 2023
1 parent 7e9f09f commit adbe4a0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/base/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/base/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace Microsoft::Console::Render
std::function<void()> _pfnFrameColorChanged;
std::function<void()> _pfnRendererEnteredErrorState;
bool _destructing = false;
bool _forceUpdateViewport = true;
bool _forceUpdateViewport = false;

#ifdef UNIT_TESTING
friend class ConptyOutputTests;
Expand Down

0 comments on commit adbe4a0

Please sign in to comment.