Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing call to UpdateViewport::UpdateViewport during tearout #15175

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ 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();
lhecker marked this conversation as resolved.
Show resolved Hide resolved
_AttachedHandlers(*this, nullptr);
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
}

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;
Copy link
Member Author

@lhecker lhecker Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(silmarillion) moving a tab to a larger window doesn't resize the control - THIS WAS AN ATLAS BUG

So, as it turns out, it's actually a DxRenderer bug which just happens to mask the other bug in Renderer, fixed here. 😄

DxRenderer doesn't use the IRenderEngine::UpdateViewport function. UpdateViewport was probably intended originally to tell the renderer the size of the text buffer.
It just happens to not cause any harm to Windows Terminal specifically, because it calls IRenderEngine::SetWindowSize and Terminal::UserResize while holding the console lock across both calls. So the renderer size and text buffer size always stay in sync. This isn't true for conhost though which uses an asynchronous approach to window resizing: The text buffer is resized on the window message thread, while the renderer thread is "free running" and only gets the current window size when it decides to paint. But by that point the window size might be different from the text buffer size.
This causes DxRenderer to crash with a SIGSEGV when you resize the OpenConsole window too quickly.


// 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also scares me, since it impacts GDI and WDDM and BGFX!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s more correct however since the only reason this member exists is because EnablePainting overwrites _viewport which it absolutely should not do. There’s no guarantee that the IRenderData has a valid viewport at that point. Because it overwrites _viewport we need this Boolean to ensure UpdateViewport is called anyways. So in a sense this is more correct because it puts the overwrite to where the mistake is happening in the first place.


#ifdef UNIT_TESTING
friend class ConptyOutputTests;
Expand Down