Clicking on a tab sometimes causes a crash #1579

Open
opened 2026-01-30 22:31:02 +00:00 by claunia · 0 comments
Owner

Originally created by @AndrewMSHowe on GitHub (Jun 9, 2019).

Originally assigned to: @DHowett-MSFT on GitHub.

Environment

I don't think it matters; commit 2da5b0b146

Steps to reproduce

Add some tabs, close some tabs. Might have to fiddle about with focus or something. It doesn't always happen straight away.

Expected behavior

It doesn't crash.

Actual behavior

It crashes, losing all your tabs.

The crash is here, on line 93 of Microsoft.Terminal.TerminalControl.h in Title():

check_hresult(WINRT_SHIM(Microsoft::Terminal::TerminalControl::ITermControl)->get_Title(&value));

The calling code is at line 1037..1041 of App.cpp in GetTitle():

                try
                {
                    return _GetFocusedControl().Title();
                }
                CATCH_LOG();

And the caller of that was _OnTabSelectionChanged().

Unfortunately it is not a thrown exception but an access violation, so the C++ exception handling doesn't help.

Inside _GetFocusedControl(), it would be possible for _GetFocusedTabIndex() to return -1, but it doesn't seem to be in this case. Also it could conceivably return >= _tabs.size() but it isn't doing that either. The problem is that _GetFocusedTerminalControl() returns nullptr, which according to its documentation is a reasonable thing to do.

I changed the code inside the try{} to:

                    auto focusedControl = _GetFocusedControl();
                    if (focusedControl)
                        return focusedControl.Title();

This seems to stop it crashing. But there are other places where _GetFocusedControl() is called without checking for a null result. So perhaps another tab should be considered focused, or something.

Also if you create shells quickly, some of them end up with no title. I think that's related, because if you click on one of those tabs, the window title (can be seen by hovering over the app's icon in the taskbar) is "Windows Terminal" which is GetTitle()s default.

Originally created by @AndrewMSHowe on GitHub (Jun 9, 2019). Originally assigned to: @DHowett-MSFT on GitHub. <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment I don't think it matters; commit 2da5b0b14682f5522b84116b3e6a6688de3c7423 # Steps to reproduce Add some tabs, close some tabs. Might have to fiddle about with focus or something. It doesn't always happen straight away. # Expected behavior It doesn't crash. # Actual behavior It crashes, losing all your tabs. The crash is here, on line 93 of Microsoft.Terminal.TerminalControl.h in Title(): ` check_hresult(WINRT_SHIM(Microsoft::Terminal::TerminalControl::ITermControl)->get_Title(&value)); ` The calling code is at line 1037..1041 of App.cpp in GetTitle(): ``` try { return _GetFocusedControl().Title(); } CATCH_LOG(); ``` And the caller of that was _OnTabSelectionChanged(). Unfortunately it is not a thrown exception but an access violation, so the C++ exception handling doesn't help. Inside _GetFocusedControl(), it would be possible for _GetFocusedTabIndex() to return -1, but it doesn't seem to be in this case. Also it could conceivably return >= _tabs.size() but it isn't doing that either. The problem is that _GetFocusedTerminalControl() returns nullptr, which according to its documentation is a reasonable thing to do. I changed the code inside the try{} to: ``` auto focusedControl = _GetFocusedControl(); if (focusedControl) return focusedControl.Title(); ``` This seems to stop it crashing. But there are other places where _GetFocusedControl() is called without checking for a null result. So perhaps another tab should be considered focused, or something. Also if you create shells quickly, some of them end up with no title. I think that's related, because if you click on one of those tabs, the window title (can be seen by hovering over the app's icon in the taskbar) is "Windows Terminal" which is GetTitle()s default.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1579