Skip to content

Commit

Permalink
When win32 is resizing the viewport, make sure Right > Left (#7768)
Browse files Browse the repository at this point in the history
Sometimes when we were sliding the viewport to fit inside the buffer, we
would end up with left > right.

That would cause us to crash down the line when rendering.

Fixes MSFT:28387423
Fixes #7744
  • Loading branch information
DHowett authored Sep 28, 2020
1 parent f28ec65 commit c3b3f5f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,14 @@ void SCREEN_INFORMATION::_InternalSetViewportSize(const COORD* const pcoordSize,
}

// Bottom and right cannot pass the final characters in the array.
srNewViewport.Right = std::min(srNewViewport.Right, gsl::narrow<SHORT>(coordScreenBufferSize.X - 1));
const SHORT offRightDelta = srNewViewport.Right - (coordScreenBufferSize.X - 1);
if (offRightDelta > 0) // the viewport was off the right of the buffer...
{
// ...so slide both left/right back into the buffer. This will prevent us
// from having a negative width later.
srNewViewport.Right -= offRightDelta;
srNewViewport.Left = std::max<SHORT>(0, srNewViewport.Left - offRightDelta);
}
srNewViewport.Bottom = std::min(srNewViewport.Bottom, gsl::narrow<SHORT>(coordScreenBufferSize.Y - 1));

// See MSFT:19917443
Expand Down

0 comments on commit c3b3f5f

Please sign in to comment.