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 crash when closing panes very quickly #17450

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
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
24 changes: 20 additions & 4 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,13 @@ void Pane::_ContentLostFocusHandler(const winrt::Windows::Foundation::IInspectab
// - <none>
void Pane::Close()
{
_setPaneContent(nullptr);
if (!_content)
{
return;
}

// Fire our Closed event to tell our parent that we should be removed.
_setPaneContent(nullptr);
Closed.raise(nullptr, nullptr);
}

Expand Down Expand Up @@ -1430,7 +1435,7 @@ void Pane::_CloseChild(const bool closeFirst)

// Reattach the TermControl to our grid.
_root.Children().Append(_borderFirst);
const auto& control{ _content.GetRoot() };
const auto control = _content ? _content.GetRoot() : nullptr;
_borderFirst.Child(control);

// Make sure to set our _splitState before focusing the control. If you
Expand All @@ -1450,7 +1455,10 @@ void Pane::_CloseChild(const bool closeFirst)
// focus our control now. This should trigger our own GotFocus event.
if (usedToFocusClosedChildsTerminal || _lastActive)
{
_content.Focus(FocusState::Programmatic);
if (_content)
{
_content.Focus(FocusState::Programmatic);
}

// See GH#7252
// Manually fire off the GotFocus event. Typically, this is done
Expand Down Expand Up @@ -1711,7 +1719,7 @@ void Pane::_SetupChildCloseHandlers()
IPaneContent Pane::_takePaneContent()
{
_closeRequestedRevoker.revoke();
return std::move(_content);
return _content ? std::move(_content) : nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old code should work even if _content == nullptr. It's like moving an empty vector<>.

}

// This method safely sets the content of the Pane. It'll ensure to revoke and
Expand Down Expand Up @@ -2943,6 +2951,10 @@ void Pane::FinalizeConfigurationGivenDefault()
// - Returns true if the pane or one of its descendants is read-only
bool Pane::ContainsReadOnly() const
{
if (!_content)
{
return false;
}
return _IsLeaf() ? _content.ReadOnly() : (_firstChild->ContainsReadOnly() || _secondChild->ContainsReadOnly());
}

Expand All @@ -2956,6 +2968,10 @@ bool Pane::ContainsReadOnly() const
// - <none>
void Pane::CollectTaskbarStates(std::vector<winrt::TerminalApp::TaskbarState>& states)
{
if (!_content)
{
return;
}
if (_IsLeaf())
{
auto tbState{ winrt::make<winrt::TerminalApp::implementation::TaskbarState>(_content.TaskbarState(),
Expand Down
Loading