From 7d790c7c6164fe4ea848ab764a00fd1a5309bdd1 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 23 Aug 2024 12:49:11 -0500 Subject: [PATCH] Prevent a crash when holding enter when creating a tab (#17788) I guess I didn't realize that `SendCharEvent` could get called before `Create`. In that scenario, `enter` would hit the automark codepath (due to #17761), then crash because there was no text buffer. Pretty easy to prevent. Closes #17776 --- src/cascadia/TerminalCore/Terminal.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 8a82d4d91a..165af0e3b0 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -711,7 +711,7 @@ TerminalInput::OutputType Terminal::SendCharEvent(const wchar_t ch, const WORD s // * AND we're not in the alt buffer // // Then treat this line like it's a prompt mark. - if (_autoMarkPrompts) + if (_autoMarkPrompts && _mainBuffer && !_inAltBuffer()) { // We need to be a little tricky here, to try and support folks that are // auto-marking prompts, but don't necessarily have the rest of shell @@ -725,10 +725,10 @@ TerminalInput::OutputType Terminal::SendCharEvent(const wchar_t ch, const WORD s // // (TextBuffer::_createPromptMarkIfNeeded does that work for us) - const bool createdMark = _activeBuffer().StartOutput(); + const bool createdMark = _mainBuffer->StartOutput(); if (createdMark) { - _activeBuffer().ManuallyMarkRowAsPrompt(_activeBuffer().GetCursor().GetPosition().y); + _mainBuffer->ManuallyMarkRowAsPrompt(_mainBuffer->GetCursor().GetPosition().y); // This changed the scrollbar marks - raise a notification to update them _NotifyScrollEvent();