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

Fixed self reference capture in Tab and TerminalPage #3835

Merged
13 commits merged into from
Dec 5, 2019

Conversation

mkitzan
Copy link
Contributor

@mkitzan mkitzan commented Dec 4, 2019

Summary of the Pull Request

Every lambda capture in Tab and TerminalPage has been changed from capturing raw this to std::weak_ptr<Tab> or winrt::weak_ref<TerminalPage>. Lambda bodies have been changed to check the weak reference before use.

Capturing raw this in Tab's title change event handler was the root cause of #3776, and is fixed in this PR among other instance of raw this capture.

The lambda fixes to TerminalPage are unrelated to the core issue addressed in the PR checklist. Because I was already editing TerminalPage, figured I'd do a weak_ref pass.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

Tab now inherits from enable_shared_from_this, which enable accessing Tab objects as std::weak_ptr<Tab> objects. All instances of lambdas capturing this now capture std::weak_ptr<Tab> instead. TerminalPage is a WinRT type which supports winrt::weak_ref<TerminalPage>. All previous instance of TerminalPage lambdas capturing this has been replaced to capture winrt::weak_ref<TerminalPage>. These weak pointers/references can only be created after object construction necessitating for Tab a new function called after construction to bind lambdas.

Any anomalous crash related to the following functionality during closing a tab or WT may be fixed by this PR:

  • Tab icon updating
  • Tab text updating
  • Tab dragging
  • Clicking new tab button
  • Changing active pane
  • Closing an active tab
  • Clicking on a tab
  • Creating the new tab flyout menu

Sorry about all the commits. Will fix my fork after this PR! 😅

Validation Steps Performed

Attempted to repro the steps indicated in issue #3776 with the new changes and failed. When before the changes, the issue could consistently be reproed.

@mkitzan
Copy link
Contributor Author

mkitzan commented Dec 4, 2019

Azure pipeline got stuck in unit testing again. I imagine I don't have the god power /azp run. Sorry for the hassle.

@mkitzan mkitzan marked this pull request as ready for review December 4, 2019 21:38
@DHowett-MSFT
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Overall this looks okay to me, but I'm mildly worried about that one _rearrangeFrom change, so I'm going to mark myself as changes requested to make sure that's answered.

Thanks!

src/cascadia/TerminalApp/TerminalPage.cpp Show resolved Hide resolved
src/cascadia/TerminalApp/Tab.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 5, 2019
Copy link
Contributor Author

@mkitzan mkitzan left a comment

Choose a reason for hiding this comment

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

Thanks for the review @zadjii-msft. I'll commit a fix for these.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 5, 2019
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Hopefully this should resolve most of the crashes we've been seeing with this latest release. Thanks for the help!

@zadjii-msft zadjii-msft added Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news. Needs-Second It's a PR that needs another sign-off labels Dec 5, 2019
@mkitzan
Copy link
Contributor Author

mkitzan commented Dec 5, 2019

Happy to help! Also, feel free to assign any goon work to me. I'm sure there's a lot of issues in the backlog with identified solutions that just need a goon to implement them.

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 5, 2019
@ghost
Copy link

ghost commented Dec 5, 2019

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 7b9728b into microsoft:master Dec 5, 2019
@zadjii-msft
Copy link
Member

feel free to assign any goon work to me. I'm sure there's a lot of issues in the backlog with identified solutions that just need a goon to implement them.

Be careful what you wish for 😜 I'll look for some things that might be up your alley

@mkitzan mkitzan deleted the fix-tab-reference-capture branch December 5, 2019 23:27
DHowett-MSFT pushed a commit that referenced this pull request Dec 11, 2019
<!-- 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)? -->
Every lambda capture in `Tab` and `TerminalPage` has been changed from capturing raw `this` to `std::weak_ptr<Tab>` or `winrt::weak_ref<TerminalPage>`. Lambda bodies have been changed to check the weak reference before use.

Capturing raw `this` in `Tab`'s [title change event handler](https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalApp/Tab.cpp#L299) was the root cause of #3776, and is fixed in this PR among other instance of raw `this` capture.

The lambda fixes to `TerminalPage` are unrelated to the core issue addressed in the PR checklist. Because I was already editing `TerminalPage`, figured I'd do a [weak_ref pass](#3776 (comment)).

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? -->

<!-- Please review the items on the PR checklist before submitting-->
* [x] Closes #3776, potentially #2248, likely closes others
* [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: #3776

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
`Tab` now inherits from `enable_shared_from_this`, which enable accessing `Tab` objects as `std::weak_ptr<Tab>` objects. All instances of lambdas capturing `this` now capture `std::weak_ptr<Tab>` instead. `TerminalPage` is a WinRT type which supports `winrt::weak_ref<TerminalPage>`. All previous instance of `TerminalPage` lambdas capturing `this` has been replaced to capture `winrt::weak_ref<TerminalPage>`. These weak pointers/references can only be created after object construction necessitating for `Tab` a new function called after construction to bind lambdas.

Any anomalous crash related to the following functionality during closing a tab or WT may be fixed by this PR:
- Tab icon updating
- Tab text updating
- Tab dragging
- Clicking new tab button
- Changing active pane
- Closing an active tab
- Clicking on a tab
- Creating the new tab flyout menu

Sorry about all the commits. Will fix my fork after this PR! 😅

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
Attempted to repro the steps indicated in issue #3776 with the new changes and failed. When before the changes, the issue could consistently be reproed.

(cherry picked from commit 7b9728b)
@ghost
Copy link

ghost commented Dec 12, 2019

🎉Windows Terminal Preview v0.7.3451.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Jan 14, 2020

🎉Windows Terminal Preview v0.8.10091.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when opening and closing a tab
4 participants