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 a crash on restore down #2149

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 34 additions & 0 deletions src/host/VtIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,37 @@ void VtIo::_ShutdownIfNeeded()
ServiceLocator::RundownAndExit(ERROR_BROKEN_PIPE);
}
}

// Method Description:
// - Tell the vt renderer to begin a resize operation. During a resize
// operation, the vt renderer should _not_ request to be repainted during a
// text buffer circling event. Any callers of this method should make sure to
// call EndResize to make sure the renderer returns to normal behavior.
// See GH#1795 for context on this method.
// Arguments:
// - <none>
// Return Value:
// - <none>
void VtIo::BeginResize()
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
if (_pVtRenderEngine)
{
_pVtRenderEngine->BeginResizeRequest();
}
}

// Method Description:
// - Tell the vt renderer to end a resize operation.
// See BeginResize for more details.
// See GH#1795 for context on this method.
// Arguments:
// - <none>
// Return Value:
// - <none>
void VtIo::EndResize()
{
if (_pVtRenderEngine)
{
_pVtRenderEngine->EndResizeRequest();
}
}
3 changes: 3 additions & 0 deletions src/host/VtIo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace Microsoft::Console::VirtualTerminal
void CloseInput() override;
void CloseOutput() override;

void BeginResize();
void EndResize();

private:
// After CreateIoHandlers is called, these will be invalid.
wil::unique_hfile _hInput;
Expand Down
13 changes: 13 additions & 0 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,19 @@ bool SCREEN_INFORMATION::IsMaximizedY() const
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
NTSTATUS status = STATUS_SUCCESS;

// If we're in conpty mode, suppress any immediate painting we might do
// during the resize.
if (gci.IsInVtIoMode())
{
gci.GetVtIo()->BeginResize();
}
auto endResize = wil::scope_exit([&] {
if (gci.IsInVtIoMode())
{
gci.GetVtIo()->EndResize();
}
});

// cancel any active selection before resizing or it will not necessarily line up with the new buffer positions
Selection::Instance().ClearSelection();

Expand Down
16 changes: 12 additions & 4 deletions src/renderer/vt/invalidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,19 @@ using namespace Microsoft::Console::Render;
// - S_OK
[[nodiscard]] HRESULT VtEngine::InvalidateCircling(_Out_ bool* const pForcePaint) noexcept
{
*pForcePaint = true;
// If we're in the middle of a resize request, don't try to immediately start a frame.
if (_inResizeRequest)
{
*pForcePaint = false;
}
else
{
*pForcePaint = true;

// Keep track of the fact that we circled, we'll need to do some work on
// end paint to specifically handle this.
_circled = true;
// Keep track of the fact that we circled, we'll need to do some work on
// end paint to specifically handle this.
_circled = true;
}

return S_OK;
}
Expand Down
29 changes: 29 additions & 0 deletions src/renderer/vt/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ VtEngine::VtEngine(_In_ wil::unique_hfile pipe,
_terminalOwner{ nullptr },
_newBottomLine{ false },
_deferredCursorPos{ INVALID_COORDS },
_inResizeRequest{ false },
_trace{}
{
#ifndef UNIT_TESTING
Expand Down Expand Up @@ -417,3 +418,31 @@ HRESULT VtEngine::RequestCursor() noexcept
RETURN_IF_FAILED(_Flush());
return S_OK;
}

// Method Description:
// - Tell the vt renderer to begin a resize operation. During a resize
// operation, the vt renderer should _not_ request to be repainted during a
// text buffer circling event. Any callers of this method should make sure to
// call EndResize to make sure the renderer returns to normal behavior.
// See GH#1795 for context on this method.
// Arguments:
// - <none>
// Return Value:
// - <none>
void VtEngine::BeginResizeRequest()
{
_inResizeRequest = true;
}

// Method Description:
// - Tell the vt renderer to end a resize operation.
// See BeginResize for more details.
// See GH#1795 for context on this method.
// Arguments:
// - <none>
// Return Value:
// - <none>
void VtEngine::EndResizeRequest()
{
_inResizeRequest = false;
}
3 changes: 3 additions & 0 deletions src/renderer/vt/vtrenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ namespace Microsoft::Console::Render
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring& str) noexcept = 0;

void SetTerminalOwner(Microsoft::Console::ITerminalOwner* const terminalOwner);
void BeginResizeRequest();
void EndResizeRequest();

protected:
wil::unique_hfile _hFile;
Expand Down Expand Up @@ -132,6 +134,7 @@ namespace Microsoft::Console::Render
Microsoft::Console::ITerminalOwner* _terminalOwner;

Microsoft::Console::VirtualTerminal::RenderTracing _trace;
bool _inResizeRequest{ false };

[[nodiscard]] HRESULT _Write(std::string_view const str) noexcept;
[[nodiscard]] HRESULT _WriteFormattedString(const std::string* const pFormat, ...) noexcept;
Expand Down
2 changes: 2 additions & 0 deletions src/terminal/adapter/InteractDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ bool InteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulatio
}
break;
case DispatchTypes::WindowManipulationType::ResizeWindowInCharacters:
// TODO:GH#1765 We should introduce a better `ResizeConpty` function to
// the ConGetSet interface, that specifically handles a conpty resize.
if (cParams == 2)
{
fSuccess = DispatchCommon::s_ResizeWindow(*_pConApi, rgusParams[1], rgusParams[0]);
Expand Down