[PR #4538] [MERGED] Fix the crash when closing Terminal containing multiple tabs. #25813

Open
opened 2026-01-31 09:11:57 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/4538
Author: @leonMSFT
Created: 2/11/2020
Status: Merged
Merged: 2/11/2020
Merged by: @undefined

Base: masterHead: dev/lelian/crashonclose


📝 Commits (3)

  • 9b1b677 removing the chunk of problematic code that isn't really needed
  • 796e66a whoops didn't remove comments
  • b49ee40 Merge branch 'master' into dev/lelian/crashonclose

📊 Changes

1 file changed (+0 additions, -19 deletions)

View changed files

📝 src/cascadia/TerminalApp/TerminalPage.cpp (+0 -19)

📄 Description

The Terminal would crash when closing it when there are multiple tabs
open. This was due to TerminalPage attempting to select a nonexistent
tab.

The block of code that was removed was causing issues when trying to
close all tabs at once. The way we close all our tabs in
_CloseAllTabs() was by repeatedly calling
_RemoveTabViewItemByIndex(0) until _tabs.Size() == 0. The problem
was that _RemoveTabViewItemByIndex would eventually call a coroutine
to set the next tab as the SelectedItem after removing a tab. The
coroutine would then pass control back to _CloseAllTabs() to finish
its loop, and by the time the coroutine resumes control, _tabs and
TabView().TabItems() would both be empty and it would crash attempting
to focus a tab.

Luckily, the functionality that this block of code provided is really no
longer needed . This code was used to focus on the next tab after
closing a tab. This might have been written way back when TabView
didn't have this functionality built in. It seems now that after
removing a TabItem from the TabView, the SelectedItem of the
TabView automatically updates, making this block of code unnecessary.

Validation Steps Performed

Did a lot of multiple tab open and closings and closing the window after
opening a ton of tabs. No crashes seem to occur anymore!
Test cases still pass.

Closes #4482


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/4538 **Author:** [@leonMSFT](https://github.com/leonMSFT) **Created:** 2/11/2020 **Status:** ✅ Merged **Merged:** 2/11/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/lelian/crashonclose` --- ### 📝 Commits (3) - [`9b1b677`](https://github.com/microsoft/terminal/commit/9b1b67756b8c2052ad99e422d69c6e6b90d5ce75) removing the chunk of problematic code that isn't really needed - [`796e66a`](https://github.com/microsoft/terminal/commit/796e66ae0598aa740da0985a4d700038d1131852) whoops didn't remove comments - [`b49ee40`](https://github.com/microsoft/terminal/commit/b49ee409e01fa116a26cb6f296b2427f66b2a55b) Merge branch 'master' into dev/lelian/crashonclose ### 📊 Changes **1 file changed** (+0 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+0 -19) </details> ### 📄 Description The Terminal would crash when closing it when there are multiple tabs open. This was due to `TerminalPage` attempting to select a nonexistent tab. The block of code that was removed was causing issues when trying to close all tabs at once. The way we close all our tabs in `_CloseAllTabs()` was by repeatedly calling `_RemoveTabViewItemByIndex(0)` until `_tabs.Size() == 0`. The problem was that `_RemoveTabViewItemByIndex` would eventually call a coroutine to set the next tab as the `SelectedItem` after removing a tab. The coroutine would then pass control back to `_CloseAllTabs()` to finish its loop, and by the time the coroutine resumes control, `_tabs` and `TabView().TabItems()` would both be empty and it would crash attempting to focus a tab. Luckily, the functionality that this block of code provided is really no longer needed . This code was used to focus on the next tab after closing a tab. This might have been written way back when TabView didn't have this functionality built in. It seems now that after removing a `TabItem` from the `TabView`, the `SelectedItem` of the TabView automatically updates, making this block of code unnecessary. ## Validation Steps Performed Did a lot of multiple tab open and closings and closing the window after opening a ton of tabs. No crashes seem to occur anymore! Test cases still pass. Closes #4482 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:11:57 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25813