diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 92d0c153c8e..eb153ce1ed8 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -1711,7 +1711,9 @@ void Pane::_SetupChildCloseHandlers() IPaneContent Pane::_takePaneContent() { _closeRequestedRevoker.revoke(); - return std::move(_content); + // we cannot return std::move(_content) because we don't want _content to be null, + // since _content gets accessed even after Close is called + return _content; } // This method safely sets the content of the Pane. It'll ensure to revoke and @@ -1721,15 +1723,14 @@ void Pane::_setPaneContent(IPaneContent content) { // The IPaneContent::Close() implementation may be buggy and raise the CloseRequested event again. // _takePaneContent() avoids this as it revokes the event handler. - if (const auto c = _takePaneContent()) + if (_takePaneContent()) { - c.Close(); + _content.Close(); } - _content = std::move(content); - - if (_content) + if (content) { + _content = std::move(content); _closeRequestedRevoker = _content.CloseRequested(winrt::auto_revoke, [this](auto&&, auto&&) { Close(); }); } }