Maximizing/Restoring when the alt buffer is active crashes conhost #1602

Closed
opened 2026-01-30 22:31:46 +00:00 by claunia · 4 comments
Owner

Originally created by @DHowett-MSFT on GitHub (Jun 11, 2019).

Originally assigned to: @zadjii-msft on GitHub.

  1. wsl
  2. printf '\e[?1049h'
  3. maximize
  4. did it crash? if not, restore
  5. did it crash? if not, maximize
  6. did it crash? if not, close this bug

Notably, the crash doesn't occur for simple resizes -- even those covering more than one side.

Originally created by @DHowett-MSFT on GitHub (Jun 11, 2019). Originally assigned to: @zadjii-msft on GitHub. 1. `wsl` 2. `printf '\e[?1049h'` 3. maximize 4. did it crash? if not, restore 5. did it crash? if not, maximize 6. did it crash? if not, close this bug Notably, the crash _doesn't_ occur for simple resizes -- even those covering more than one side.
Author
Owner

@DHowett-MSFT commented on GitHub (Jun 11, 2019):

 	OpenConsole.exe!wil::details::in1diag5::_Throw_Hr(void * callerReturnAddress, unsigned int lineNumber, const char * fileName, const char * functionName, const char * code, HRESULT hr) Line 4937	C++
 	OpenConsole.exe!wil::details::in1diag5::Throw_HrIf(void * callerReturnAddress, unsigned int lineNumber, const char * fileName, const char * functionName, const char * code, HRESULT hr, bool condition) Line 5041	C++
 	OpenConsole.exe!TextBufferCellIterator::TextBufferCellIterator(const TextBuffer & buffer, _COORD pos, const Microsoft::Console::Types::Viewport limits) Line 43	C++
 	OpenConsole.exe!TextBuffer::GetCellDataAt(const _COORD at, const Microsoft::Console::Types::Viewport limit) Line 169	C++
 	OpenConsole.exe!Microsoft::Console::Render::Renderer::_PaintBufferOutput(Microsoft::Console::Render::IRenderEngine * const pEngine) Line 579	C++
 	OpenConsole.exe!Microsoft::Console::Render::Renderer::_PaintFrameForEngine(Microsoft::Console::Render::IRenderEngine * const pEngine) Line 119	C++
 	OpenConsole.exe!Microsoft::Console::Render::Renderer::PaintFrame() Line 68	C++
 	OpenConsole.exe!Microsoft::Console::Render::RenderThread::_ThreadProc() Line 168	C++
 	OpenConsole.exe!Microsoft::Console::Render::RenderThread::s_ThreadProc(void * lpParameter) Line 151	C++
@DHowett-MSFT commented on GitHub (Jun 11, 2019): ``` OpenConsole.exe!wil::details::in1diag5::_Throw_Hr(void * callerReturnAddress, unsigned int lineNumber, const char * fileName, const char * functionName, const char * code, HRESULT hr) Line 4937 C++ OpenConsole.exe!wil::details::in1diag5::Throw_HrIf(void * callerReturnAddress, unsigned int lineNumber, const char * fileName, const char * functionName, const char * code, HRESULT hr, bool condition) Line 5041 C++ OpenConsole.exe!TextBufferCellIterator::TextBufferCellIterator(const TextBuffer & buffer, _COORD pos, const Microsoft::Console::Types::Viewport limits) Line 43 C++ OpenConsole.exe!TextBuffer::GetCellDataAt(const _COORD at, const Microsoft::Console::Types::Viewport limit) Line 169 C++ OpenConsole.exe!Microsoft::Console::Render::Renderer::_PaintBufferOutput(Microsoft::Console::Render::IRenderEngine * const pEngine) Line 579 C++ OpenConsole.exe!Microsoft::Console::Render::Renderer::_PaintFrameForEngine(Microsoft::Console::Render::IRenderEngine * const pEngine) Line 119 C++ OpenConsole.exe!Microsoft::Console::Render::Renderer::PaintFrame() Line 68 C++ OpenConsole.exe!Microsoft::Console::Render::RenderThread::_ThreadProc() Line 168 C++ OpenConsole.exe!Microsoft::Console::Render::RenderThread::s_ThreadProc(void * lpParameter) Line 151 C++ ```
Author
Owner

@zadjii-msft commented on GitHub (Sep 3, 2019):

This only repros if "Disable scroll forward" is enabled.

This surprises me, considering the alt buffer doesn't need to do anything with _virtualBottom, but something's definitely busted there.

@zadjii-msft commented on GitHub (Sep 3, 2019): This only repros if "Disable scroll forward" is _enabled_. This surprises me, considering the alt buffer doesn't need to do anything with _virtualBottom, but something's definitely busted there.
Author
Owner

@zadjii-msft commented on GitHub (Sep 3, 2019):

This code looks bad: SCREEN_INFORMATION::_InternalSetViewportSize

> OpenConsole!SCREEN_INFORMATION::_InternalSetViewportSize+0x5ca [...OpenConsole\src\host\screenInfo.cpp @ 1241] 
  OpenConsole!SCREEN_INFORMATION::_AdjustViewportSize+0x157 [...\OpenConsole\src\host\screenInfo.cpp @ 1297] 
  OpenConsole!SCREEN_INFORMATION::ProcessResizeWindow+0x14c [...\OpenConsole\src\host\screenInfo.cpp @ 887] 
  OpenConsole!Microsoft::Console::Interactivity::Win32::Window::_HandleWindowPosChanged+0x135 [...\OpenConsole\src\interactivity\win32\WindowProc.cpp @ 812] 
  OpenConsole!Microsoft::Console::Interactivity::Win32::Window::ConsoleWindowProc+0x101c [...\OpenConsole\src\interactivity\win32\WindowProc.cpp @ 478] 
    if (gci.IsTerminalScrolling() && newViewport.Height() != _viewport.Height())
    {
        const short newTop = static_cast<short>(std::max(0, _virtualBottom - (newViewport.Height() - 1)));

        newViewport = Viewport::FromDimensions(COORD({ newViewport.Left(), newTop }), newViewport.Dimensions());
    }

During the resize down, we're resizing the alt buffer here. Prior to the newViewport = Viewport::FromDimensions(... line, members have the following values:

Variable value
newTop 76
_virtualBottom 105
newViewport {LT(0, 0) RB(119, 29) [120 x 30]}
_viewport {LT(0, 0) RB(370, 105) [371 x 106]}

Looks like we're trying to set the top of the new viewport so that the virtual bottom stays anchored to the new viewport's bottom. However, this only makes sense when the viewport is getting bigger, not when it's getting smaller. In that scenario, we'll end up setting the top to somewhere in the middle of the buffer, and then be real confused by the next paint.

@zadjii-msft commented on GitHub (Sep 3, 2019): This code looks bad: `SCREEN_INFORMATION::_InternalSetViewportSize` ``` > OpenConsole!SCREEN_INFORMATION::_InternalSetViewportSize+0x5ca [...OpenConsole\src\host\screenInfo.cpp @ 1241] OpenConsole!SCREEN_INFORMATION::_AdjustViewportSize+0x157 [...\OpenConsole\src\host\screenInfo.cpp @ 1297] OpenConsole!SCREEN_INFORMATION::ProcessResizeWindow+0x14c [...\OpenConsole\src\host\screenInfo.cpp @ 887] OpenConsole!Microsoft::Console::Interactivity::Win32::Window::_HandleWindowPosChanged+0x135 [...\OpenConsole\src\interactivity\win32\WindowProc.cpp @ 812] OpenConsole!Microsoft::Console::Interactivity::Win32::Window::ConsoleWindowProc+0x101c [...\OpenConsole\src\interactivity\win32\WindowProc.cpp @ 478] ``` ```c++ if (gci.IsTerminalScrolling() && newViewport.Height() != _viewport.Height()) { const short newTop = static_cast<short>(std::max(0, _virtualBottom - (newViewport.Height() - 1))); newViewport = Viewport::FromDimensions(COORD({ newViewport.Left(), newTop }), newViewport.Dimensions()); } ``` During the resize down, we're resizing the alt buffer here. Prior to the `newViewport = Viewport::FromDimensions(...` line, members have the following values: | Variable | value | | ------------- | ------------- | | newTop | 76 | | _virtualBottom | 105 | | newViewport | {LT(0, 0) RB(119, 29) [120 x 30]} | | _viewport | {LT(0, 0) RB(370, 105) [371 x 106]} | Looks like we're trying to set the top of the new viewport so that the virtual bottom stays anchored to the new viewport's bottom. However, this only makes sense when the viewport is getting _bigger_, not when it's getting smaller. In that scenario, we'll end up setting the top to somewhere in the middle of the buffer, and then be real confused by the next paint.
Author
Owner

@ghost commented on GitHub (Sep 24, 2019):

:tada:This issue was addressed in #2666, which has now been successfully released as Windows Terminal Preview v0.5.2661.0.🎉

Handy links:

@ghost commented on GitHub (Sep 24, 2019): :tada:This issue was addressed in #2666, which has now been successfully released as `Windows Terminal Preview v0.5.2661.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.5.2661.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1602