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 last tab #892

Closed
wants to merge 8 commits into from

Conversation

fghzxm
Copy link
Contributor

@fghzxm fghzxm commented May 18, 2019

Summary of the Pull Request

This commit fixes crashes that happen when the last tab is being closed.

References

None.

PR Checklist

  • Closes #xxx
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

Commit bc69d1a adds code that closes
the window when the last tab is being closed, but code that should only
be executed when closing one of multiple open tabs continues to be
executed. This leads to App::_RemoveTabViewItem trying to call
TabView::SelectedIndex(1) when there is only 1 tab remaining in the
TabView, resulting in an argument exception.

This commit fixes crashes that happen when the last tab is being closed.

Commit bc69d1a adds code that closes
the window when the last tab is being closed, but code that should only
be executed when closing one of multiple open tabs continues to be
executed.  This leads to App::_RemoveTabViewItem trying to call
TabView::SelectedIndex(1) when there is only 1 tab remaining in the
TabView, resulting in an argument exception.

Signed-off-by: Fred Miller <fghzxm@outlook.com>
Signed-off-by: Fred Miller <fghzxm@outlook.com>
Signed-off-by: Fred Miller <fghzxm@outlook.com>
Signed-off-by: Fred Miller <fghzxm@outlook.com>
src/cascadia/TerminalApp/App.cpp Outdated Show resolved Hide resolved
_tabView.Items().RemoveAt(tabIndexFromControl);

// ensure tabs and focus is sync
_tabView.SelectedIndex(tabIndexFromControl > 0 ? tabIndexFromControl - 1 : 0);
Copy link
Member

Choose a reason for hiding this comment

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

This got removed. But I'm noticing it's similar to line 863. Should we be removing this line and updating/replacing line 863 with this?

Copy link
Contributor Author

@fghzxm fghzxm May 20, 2019

Choose a reason for hiding this comment

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

From my experiments, line 867 is unnecessary. The SelectedIndex property is maintained correctly by the TabView component when a tab is closed. Fixed in f8efdb9. After further investigation I came to believe that issue #708 is not from a bug in Terminal, (which means PR #737 probably did not actually fix it,) but from one in MUX.Controls.TabView, namely it failing to maintain its SelectedIndex property in the case of one or more TabViewItems are being removed from it. I'm undoing f8efdb9 and instead opening an issue at MUX. Meanwhile unresolving.

{
_tabView.SelectedIndex(removingTabIndex > 0 ? removingTabIndex - 1 : 1);
}
_tabView.Items().RemoveAt(removingTabIndex);
Copy link
Member

Choose a reason for hiding this comment

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

Should this be moved down with line 869 like it was before? Or does closing the window (line 855) basically handle the logic of removing the XAML TabView Control?

This commit restores `App::_RemoveTabViewItem`'s behavior of removing
the last Tab control from the TabView when the tab being closed is the
last remaining, and additionally destructs the TabView control as
suggested
(microsoft#892 (comment)).

Also restructures the function to handle 2 circumstances (whether the
tab being closed is the last one or not) explicitly.

Signed-off-by: Fred Miller <fghzxm@outlook.com>
Suggested at
microsoft#892 (comment).

Signed-off-by: Fred Miller <fghzxm@outlook.com>
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Noticed regression to Bug #708 (fixed in PR #737). Please fix.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 20, 2019
microsoft#892 (review)

Signed-off-by: Fred Miller <fghzxm@outlook.com>
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 21, 2019
microsoft#892 (comment)

Signed-off-by: Fred Miller <fghzxm@outlook.com>
@fghzxm
Copy link
Contributor Author

fghzxm commented May 22, 2019

I'm closing this PR for now since PR #818 seems to obsolete this. However I'm still monitoring microsoft/microsoft-ui-xaml#629 which I believe very likely contains the bug of TabView::OnItemsChanged failing to maintain SelectedIndex correctly. In fact, the extra logic PR #818 introduces really looks like they should be part of TabView::OnItemsChanged itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants