Terminal: Clicking on a tab sometimes causes a crash

Created on 9 Jun 2019  路  1Comment  路  Source: microsoft/terminal

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.

Area-User Interface Issue-Bug Needs-Tag-Fix Product-Terminal Severity-Crash

Most helpful comment

Found better repro steps:

  1. Hold down Ctrl-T
  2. Observe some tabs appearing shorter, with no title.
  3. Retire to a safe distance.
  4. Click on one of the short tabs.

>All comments

Found better repro steps:

  1. Hold down Ctrl-T
  2. Observe some tabs appearing shorter, with no title.
  3. Retire to a safe distance.
  4. Click on one of the short tabs.
Was this page helpful?
0 / 5 - 0 ratings