diff --git a/src/renderer/vt/XtermEngine.cpp b/src/renderer/vt/XtermEngine.cpp index 413779b047..730873097d 100644 --- a/src/renderer/vt/XtermEngine.cpp +++ b/src/renderer/vt/XtermEngine.cpp @@ -112,7 +112,10 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe, // by prepending a cursor off. if (_lastCursorIsVisible != Tribool::False) { - _buffer.insert(0, "\x1b[?25l"); + { + auto buffer{ _buffer.lock() }; + buffer->insert(0, "\x1b[?25l"); + } _lastCursorIsVisible = Tribool::False; } // If the cursor was NOT previously visible, then that's fine! we don't diff --git a/src/renderer/vt/paint.cpp b/src/renderer/vt/paint.cpp index dda813b92f..2c775579f7 100644 --- a/src/renderer/vt/paint.cpp +++ b/src/renderer/vt/paint.cpp @@ -94,22 +94,6 @@ using namespace Microsoft::Console::Types; RETURN_IF_FAILED(_MoveCursor(_deferredCursorPos)); } - // If this frame was triggered because we encountered a VT sequence which - // required the buffered state to get printed, we don't want to flush this - // frame to the pipe. That might result in us rendering half the output of a - // particular frame (as emitted by the client). - // - // Instead, we'll leave this frame in _buffer, and just keep appending to - // it as needed. - if (_noFlushOnEnd) [[unlikely]] - { - _noFlushOnEnd = false; - } - else - { - RETURN_IF_FAILED(_Flush()); - } - return S_OK; } @@ -122,8 +106,23 @@ using namespace Microsoft::Console::Types; // Return Value: // - S_FALSE since we do nothing. [[nodiscard]] HRESULT VtEngine::Present() noexcept -{ - return S_FALSE; +{ // If this frame was triggered because we encountered a VT sequence which + // required the buffered state to get printed, we don't want to flush this + // frame to the pipe. That might result in us rendering half the output of a + // particular frame (as emitted by the client). + // + // Instead, we'll leave this frame in _buffer, and just keep appending to + // it as needed. + if (_noFlushOnEnd) + [[unlikely]] + { + _noFlushOnEnd = false; + } + else + { + RETURN_IF_FAILED(_Flush()); + } + return S_OK; } [[nodiscard]] HRESULT VtEngine::ResetLineTransform() noexcept @@ -552,10 +551,11 @@ using namespace Microsoft::Console::Types; // Write the actual text string. If we're using a soft font, the character // set should have already been selected, so we just need to map our internal // representation back to ASCII (handled by the _WriteTerminalDrcs method). - if (_usingSoftFont) [[unlikely]] - { - RETURN_IF_FAILED(VtEngine::_WriteTerminalDrcs({ _bufferLine.data(), cchActual })); - } + if (_usingSoftFont) + [[unlikely]] + { + RETURN_IF_FAILED(VtEngine::_WriteTerminalDrcs({ _bufferLine.data(), cchActual })); + } else { RETURN_IF_FAILED(VtEngine::_WriteTerminalUtf8({ _bufferLine.data(), cchActual })); diff --git a/src/renderer/vt/state.cpp b/src/renderer/vt/state.cpp index 29a8657cd5..d45796d29e 100644 --- a/src/renderer/vt/state.cpp +++ b/src/renderer/vt/state.cpp @@ -93,7 +93,10 @@ try #endif // TODO GH10001: Replace me with REP - _buffer.append(n, c); + { + auto buffer{ _buffer.lock() }; + buffer->append(n, c); + } return S_OK; } CATCH_RETURN(); @@ -129,7 +132,8 @@ CATCH_RETURN(); try { - _buffer.append(str); + auto buffer{ _buffer.lock() }; + buffer->append(str); return S_OK; } @@ -140,8 +144,12 @@ CATCH_RETURN(); { if (_hFile) { - auto fSuccess = !!WriteFile(_hFile.get(), _buffer.data(), gsl::narrow_cast(_buffer.size()), nullptr, nullptr); - _buffer.clear(); + bool fSuccess = false; + { + auto buffer{ _buffer.lock() }; + fSuccess = !!WriteFile(_hFile.get(), buffer->data(), gsl::narrow_cast(buffer->size()), nullptr, nullptr); + buffer->clear(); + } if (!fSuccess) { _exitResult = HRESULT_FROM_WIN32(GetLastError()); diff --git a/src/renderer/vt/vtrenderer.hpp b/src/renderer/vt/vtrenderer.hpp index 3ba1e702af..4fad26b1a5 100644 --- a/src/renderer/vt/vtrenderer.hpp +++ b/src/renderer/vt/vtrenderer.hpp @@ -20,6 +20,7 @@ Author(s): #include "tracing.hpp" #include #include +#include // fwdecl unittest classes #ifdef UNIT_TESTING @@ -93,7 +94,7 @@ namespace Microsoft::Console::Render protected: wil::unique_hfile _hFile; - std::string _buffer; + til::shared_mutex _buffer; std::string _formatBuffer; std::string _conversionBuffer;