[PR #3908] [MERGED] Fixed self capture in TermControl #25552

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/3908
Author: @mkitzan
Created: 12/11/2019
Status: Merged
Merged: 12/13/2019
Merged by: @undefined

Base: masterHead: fix-termcontrol-lambdas


📝 Commits (5)

  • bb67a00 Fixed TermControl lambda captures
  • 8afce7f Should've ran Format Document the first time
  • a81fdc1 Changes for auto_revoke
  • d271c33 PR review revision commit
  • 7729685 Tick now takes get_weak()

📊 Changes

2 files changed (+89 additions, -81 deletions)

View changed files

📝 src/cascadia/TerminalControl/TermControl.cpp (+88 -81)
📝 src/cascadia/TerminalControl/TermControl.h (+1 -0)

📄 Description

Summary of the Pull Request

An asynchronous event handler capturing raw this in TermControl was causing an exception to be thrown when a scroll update event occurred after closing the active tab. This PR replaces all non-auto_revoke lambda captures in TermControl to capture (and validate) a winrt::weak_ref instead of using raw this.

References

PR Checklist

  • Closes Bug Report- It disappear ! (#2947)
  • 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: #2947

Detailed Description of the Pull Request / Additional comments

TermControl is already a WinRT type so no changes were required to enable the winrt::weak_ref functionality. There was only one strange change I had to make. In the destructor's helper function Close, I had to remove two calls to Stop which were throwing under some circumstances. Fortunately, these calls don't appear to be critical, but definitely a spot to look into when reviewing this PR.

Beyond scrolling, any anomalous crash related to the following functionality while closing a tab or WT may be fixed by this PR:

  • Settings updating
  • Changing background color

Validation Steps Performed

Before these changes I was able to consistently repro the issue in #2947. Now, I can no longer repro the issue.


🔄 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/3908 **Author:** [@mkitzan](https://github.com/mkitzan) **Created:** 12/11/2019 **Status:** ✅ Merged **Merged:** 12/13/2019 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `fix-termcontrol-lambdas` --- ### 📝 Commits (5) - [`bb67a00`](https://github.com/microsoft/terminal/commit/bb67a00e24c327db9fe08f71f19bec79b6f13832) Fixed TermControl lambda captures - [`8afce7f`](https://github.com/microsoft/terminal/commit/8afce7ffe1cc7465ca75f2bd6ab68fe2f8efd3e6) Should've ran Format Document the first time - [`a81fdc1`](https://github.com/microsoft/terminal/commit/a81fdc18f2f4548ea986174ce42828b52979b0a9) Changes for auto_revoke - [`d271c33`](https://github.com/microsoft/terminal/commit/d271c33ae0d4b2480d43714090a7aba05b0e9ccf) PR review revision commit - [`7729685`](https://github.com/microsoft/terminal/commit/7729685783c4fc385df6df80a8f44b8a4eb21594) Tick now takes get_weak() ### 📊 Changes **2 files changed** (+89 additions, -81 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+88 -81) 📝 `src/cascadia/TerminalControl/TermControl.h` (+1 -0) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request An asynchronous event handler capturing raw `this` in `TermControl` was causing an exception to be thrown when a scroll update event occurred after closing the active tab. This PR replaces all non-auto_revoke lambda captures in `TermControl` to capture (and validate) a `winrt::weak_ref` instead of using raw `this`. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #2947 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [x] 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: #2947 <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments `TermControl` is already a WinRT type so no changes were required to enable the `winrt::weak_ref` functionality. There was only one strange change I had to make. In the destructor's helper function `Close`, I had to remove two calls to [`Stop`](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.dispatchertimer.stop#Windows_UI_Xaml_DispatcherTimer_Stop) which were throwing under [some circumstances](https://github.com/microsoft/terminal/issues/2947#issuecomment-562914135). Fortunately, these calls don't appear to be critical, but definitely a spot to look into when reviewing this PR. Beyond scrolling, any anomalous crash related to the following functionality while closing a tab or WT may be fixed by this PR: - Settings updating - Changing background color <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Before these changes I was able to consistently repro the issue in #2947. Now, I can no longer repro the issue. --- <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:10:16 +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#25552