From f5c8b0bca0b9edd1be404817a3cb871b98db8668 Mon Sep 17 00:00:00 2001 From: Michael Niksa Date: Fri, 24 Apr 2020 14:42:51 -0700 Subject: [PATCH] Take the lock before moving the selection endpoint out from under the renderer while it's rendering a frame. --- src/cascadia/TerminalControl/TermControl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 93dea4b4959..97ac2bf5a49 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1358,6 +1358,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation if (_terminal->IsSelectionActive() && isLeftButtonPressed) { + // Have to take the lock or we could change the endpoints out from under the renderer actively rendering. + auto lock = _terminal->LockForWriting(); + // If user is mouse selecting and scrolls, they then point at new character. // Make sure selection reflects that immediately. _SetEndSelectionPointAtCursor(point); @@ -1489,6 +1492,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation if (_autoScrollingPointerPoint.has_value()) { + // Have to take the lock because the renderer will not draw correctly if you move its endpoints while it is generating a frame. + auto lock = _terminal->LockForWriting(); + _SetEndSelectionPointAtCursor(_autoScrollingPointerPoint.value().Position()); } }