Crash when closing a tab with multiple splits from the tab context menu #12386

Closed
opened 2026-01-31 03:14:18 +00:00 by claunia · 1 comment
Owner

Originally created by @zadjii-msft on GitHub (Feb 3, 2021).

Originally assigned to: @PankajBhojwani on GitHub.

  1. open two tabs
  2. in the first, make two panes
  3. try to close the tab from the right-click "Close Tab" option.
  4. Experience exception:
    TerminalApp.dll!std::_Throw_bad_optional_access() Line 54   C++
    TerminalApp.dll!std::optional<unsigned short>::value() Line 379 C++
    TerminalApp.dll!Pane::Id() Line 1558    C++
>   TerminalApp.dll!<lambda_1a1e553ee07ffde1f0ed98f661a0b933>::operator()<winrt::Windows::Foundation::IInspectable$_ResumeCoro$1 const &,winrt::Windows::Foundation::IInspectable$_ResumeCoro$1 const &>() Line 699 C++
    TerminalApp.dll!<lambda_1a1e553ee07ffde1f0ed98f661a0b933>::operator()<winrt::Windows::Foundation::IInspectable$_InitCoro$2 const &,winrt::Windows::Foundation::IInspectable$_InitCoro$2 const &>() Line 685 C++
    TerminalApp.dll!<lambda_1a1e553ee07ffde1f0ed98f661a0b933>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::Windows::Foundation::IInspectable const &>(const winrt::Windows::Foundation::IInspectable &) Line 707 C++
    TerminalApp.dll!winrt::impl::delegate<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,<lambda_1a1e553ee07ffde1f0ed98f661a0b933>>::Invoke(void * sender, void * args) Line 883    C++
    TerminalApp.dll!winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>::operator()(const winrt::Windows::Foundation::IInspectable & sender, const winrt::Windows::Foundation::IInspectable & args) Line 2500    C++
    TerminalApp.dll!winrt::impl::invoke<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,std::nullptr_t,std::nullptr_t>(const winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable> & delegate, void * const & <args_0>, void * const & <args_1>) Line 5567  C++
    TerminalApp.dll!winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>>::operator()<std::nullptr_t,std::nullptr_t>(void * const & <args_0>, void * const & <args_1>) Line 5702 C++
    TerminalApp.dll!Pane::Close() Line 424  C++
    TerminalApp.dll!<lambda_4e44f426db787ef722ec55bc42fe1f5e>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::Windows::UI::Xaml::RoutedEventArgs const &>(const winrt::Windows::Foundation::IInspectable & __formal, const winrt::Windows::UI::Xaml::RoutedEventArgs & __formal) Line 754   C++
    TerminalApp.dll!winrt::impl::delegate<winrt::Windows::UI::Xaml::RoutedEventHandler,<lambda_4e44f426db787ef722ec55bc42fe1f5e>>::Invoke(void * sender, void * e) Line 4671    C++
    Windows.UI.Xaml.dll!DirectUI::CRoutedEventSourceBase<DirectUI::IUntypedEventSource,Windows::UI::Xaml::IRoutedEventHandler,IInspectable,Windows::UI::Xaml::IRoutedEventArgs>::Raise(IInspectable * pSource, Windows::UI::Xaml::IRoutedEventArgs * pArgs) Line 1041   C++
    Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::Invoke() Line 208 C++
    Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::PerformPointerUpAction() Line 186 C++
    Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::OnPointerReleased(Windows::UI::Xaml::Input::IPointerRoutedEventArgs * pArgs) Line 146 C++
    Windows.UI.Xaml.dll!DirectUI::ControlGenerated::OnPointerReleasedProtected(Windows::UI::Xaml::Input::IPointerRoutedEventArgs * pE) Line 1518    C++
    Windows.UI.Xaml.dll!DirectUI::Control::FireEvent(KnownEventIndex nDelegate, DirectUI::DependencyObject * pSender, IInspectable * pArgs) Line 259    C++

Which has a root cause here:

        pane->Closed([weakThis, weakPane](auto&& /*s*/, auto && /*e*/) -> winrt::fire_and_forget {
        ...
                        if (*i == pane->Id()) // <---------------- This line right here, throws. The pane's ID might be nullopt!!
                        {
                            tab->_mruPanes.erase(i);
                            break;
                        }

Turn out, the pane's ID was nullopt. So when we tried to compare the mru pane ID to the pane's ID, it tried to compare against the value of the optional, which threw.

WEIRDLY, if you add a closeTab action, and try doing this from the command palette, it doesn't repro. It also doesn't repro if you just close the tab by middle clicking it.

This is not the same bug as the "menu flyout crash" - I was very sure to not hover over the nested menu entry when doing this.

Originally created by @zadjii-msft on GitHub (Feb 3, 2021). Originally assigned to: @PankajBhojwani on GitHub. 1. open two tabs 2. in the first, make two panes 3. try to close the tab from the right-click "Close Tab" option. 4. Experience exception: ``` TerminalApp.dll!std::_Throw_bad_optional_access() Line 54 C++ TerminalApp.dll!std::optional<unsigned short>::value() Line 379 C++ TerminalApp.dll!Pane::Id() Line 1558 C++ > TerminalApp.dll!<lambda_1a1e553ee07ffde1f0ed98f661a0b933>::operator()<winrt::Windows::Foundation::IInspectable$_ResumeCoro$1 const &,winrt::Windows::Foundation::IInspectable$_ResumeCoro$1 const &>() Line 699 C++ TerminalApp.dll!<lambda_1a1e553ee07ffde1f0ed98f661a0b933>::operator()<winrt::Windows::Foundation::IInspectable$_InitCoro$2 const &,winrt::Windows::Foundation::IInspectable$_InitCoro$2 const &>() Line 685 C++ TerminalApp.dll!<lambda_1a1e553ee07ffde1f0ed98f661a0b933>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::Windows::Foundation::IInspectable const &>(const winrt::Windows::Foundation::IInspectable &) Line 707 C++ TerminalApp.dll!winrt::impl::delegate<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,<lambda_1a1e553ee07ffde1f0ed98f661a0b933>>::Invoke(void * sender, void * args) Line 883 C++ TerminalApp.dll!winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>::operator()(const winrt::Windows::Foundation::IInspectable & sender, const winrt::Windows::Foundation::IInspectable & args) Line 2500 C++ TerminalApp.dll!winrt::impl::invoke<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,std::nullptr_t,std::nullptr_t>(const winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable> & delegate, void * const & <args_0>, void * const & <args_1>) Line 5567 C++ TerminalApp.dll!winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>>::operator()<std::nullptr_t,std::nullptr_t>(void * const & <args_0>, void * const & <args_1>) Line 5702 C++ TerminalApp.dll!Pane::Close() Line 424 C++ TerminalApp.dll!<lambda_4e44f426db787ef722ec55bc42fe1f5e>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::Windows::UI::Xaml::RoutedEventArgs const &>(const winrt::Windows::Foundation::IInspectable & __formal, const winrt::Windows::UI::Xaml::RoutedEventArgs & __formal) Line 754 C++ TerminalApp.dll!winrt::impl::delegate<winrt::Windows::UI::Xaml::RoutedEventHandler,<lambda_4e44f426db787ef722ec55bc42fe1f5e>>::Invoke(void * sender, void * e) Line 4671 C++ Windows.UI.Xaml.dll!DirectUI::CRoutedEventSourceBase<DirectUI::IUntypedEventSource,Windows::UI::Xaml::IRoutedEventHandler,IInspectable,Windows::UI::Xaml::IRoutedEventArgs>::Raise(IInspectable * pSource, Windows::UI::Xaml::IRoutedEventArgs * pArgs) Line 1041 C++ Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::Invoke() Line 208 C++ Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::PerformPointerUpAction() Line 186 C++ Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::OnPointerReleased(Windows::UI::Xaml::Input::IPointerRoutedEventArgs * pArgs) Line 146 C++ Windows.UI.Xaml.dll!DirectUI::ControlGenerated::OnPointerReleasedProtected(Windows::UI::Xaml::Input::IPointerRoutedEventArgs * pE) Line 1518 C++ Windows.UI.Xaml.dll!DirectUI::Control::FireEvent(KnownEventIndex nDelegate, DirectUI::DependencyObject * pSender, IInspectable * pArgs) Line 259 C++ ``` Which has a root cause here: ```c++ pane->Closed([weakThis, weakPane](auto&& /*s*/, auto && /*e*/) -> winrt::fire_and_forget { ... if (*i == pane->Id()) // <---------------- This line right here, throws. The pane's ID might be nullopt!! { tab->_mruPanes.erase(i); break; } ``` Turn out, the pane's ID was `nullopt`. So when we tried to compare the mru pane ID to the pane's ID, it tried to compare against the value of the optional, which threw. WEIRDLY, if you add a `closeTab` action, and try doing this from the command palette, it _doesn't_ repro. It also doesn't repro if you just close the tab by middle clicking it. This is _not_ the same bug as the "menu flyout crash" - I was very sure to not hover over the nested menu entry when doing this.
Author
Owner

@ghost commented on GitHub (Feb 11, 2021):

:tada:This issue was addressed in #9028, which has now been successfully released as Windows Terminal Preview v1.6.10412.0.🎉

Handy links:

@ghost commented on GitHub (Feb 11, 2021): :tada:This issue was addressed in #9028, which has now been successfully released as `Windows Terminal Preview v1.6.10412.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.6.10412.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12386