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 a crash when closing tabs #18620

Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Feb 24, 2025

WinUI asynchronously updates its tab view items, so it may happen that
we're given a TabViewItem that still contains a TabBase which has
actually already been removed. Regressed in #15924.

Closes #18581

Validation Steps Performed

  • Close tabs rapidly with middle click
  • No crash ✅

@@ -851,6 +851,9 @@ namespace winrt::TerminalApp::implementation
{
ASSERT_UI_THREAD();

// Don't forget to call the overridden function. :)
TabBase::Shutdown();
Copy link
Member Author

Choose a reason for hiding this comment

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

(FWIW this is a Crucial part of this PR as it sets the content to null. Also, TIL: We have a tab content that is different from the pane content. Was slightly confused by that naming.)

Copy link
Member

Choose a reason for hiding this comment

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

@zadjii-msft I thought we merged terminaltab back into tabbase 😢

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-Quality Stability, Performance, Etc. Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news. labels Feb 24, 2025
@@ -851,6 +851,9 @@ namespace winrt::TerminalApp::implementation
{
ASSERT_UI_THREAD();

// Don't forget to call the overridden function. :)
TabBase::Shutdown();
Copy link
Member

Choose a reason for hiding this comment

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

@zadjii-msft I thought we merged terminaltab back into tabbase 😢

@@ -903,19 +905,39 @@ namespace winrt::TerminalApp::implementation
if (_tabPointerMiddleButtonPressed && !eventArgs.GetCurrentPoint(nullptr).Properties().IsMiddleButtonPressed())
{
_tabPointerMiddleButtonPressed = false;
if (const auto tabViewItem{ sender.try_as<MUX::Controls::TabViewItem>() })
if (auto tabViewItem = sender.try_as<MUX::Controls::TabViewItem>())
Copy link
Member

Choose a reason for hiding this comment

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

why the syntax change? was the previous one wrong?

Copy link
Member Author

@lhecker lhecker Feb 24, 2025

Choose a reason for hiding this comment

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

I believe we're alone in our usage of the auto foo{ ... } syntax. Not even the C++ Core Guidelines use it: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-auto
As you know, the brace-initializer syntax is historically overladen and rather brittle, so I see people recommend using it only for constructing explicitly named types, and I concur. In fact, since ~C++20 it's actually been going back from there with the consortium's trend towards "we can be like Rust if we have static analyzers", hence members recommending even things like int foo = bar(), despite the risk for unintentional narrowing.

@lhecker lhecker added the AutoMerge Marked for automatic merge by the bot when requirements are met label Feb 24, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit 62e7f4b into main Feb 24, 2025
17 of 19 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the dev/lhecker/18581-tab-close-crash branch February 24, 2025 18:31
DHowett pushed a commit that referenced this pull request Feb 26, 2025
WinUI asynchronously updates its tab view items, so it may happen that
we're given a `TabViewItem` that still contains a `TabBase` which has
actually already been removed. Regressed in #15924.

Closes #18581

## Validation Steps Performed
* Close tabs rapidly with middle click
* No crash ✅

(cherry picked from commit 62e7f4b)
Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgXpjpM PVTI_lADOAF3p4s4AxadtzgXsRQM
Service-Version: 1.23
@lanwin
Copy link

lanwin commented Mar 18, 2025

Is this fix related to that crash #18458 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Quality Stability, Performance, Etc. AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news.
Projects
Status: Cherry Picked
Development

Successfully merging this pull request may close these issues.

Crash when quickly closing tabs with the middle mouse button
4 participants