terminal/src
Michael Kitzan 7b9728b4a9 Fixed self reference capture in Tab and TerminalPage (#3835)
<!-- 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
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](https://github.com/microsoft/terminal/issues/3776#issuecomment-560575575).

<!-- 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 #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 -->
## 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! 😅 

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## 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.
2019-12-05 23:18:22 +00:00
..
buffer Integrate inbox changes up to 68d3b53286dd 2019-12-02 17:24:26 -08:00
cascadia Fixed self reference capture in Tab and TerminalPage (#3835) 2019-12-05 23:18:22 +00:00
host Prevent the horizontal tab character wrapping at the end of a line (#3197) 2019-12-04 13:48:09 -05:00
inc Upgrade UiaProviders to WRL::ComPtr (#3051) 2019-11-21 16:08:37 -08:00
interactivity Conhost: copy RTF to clipboard (#3595) 2019-12-05 22:29:08 +00:00
internal Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
propsheet Integrate inbox changes up to 68d3b53286dd 2019-12-02 17:24:26 -08:00
propslib Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
renderer Introduce a Universal package for Windows Terminal (#3236) 2019-11-25 16:30:45 -08:00
server Revert locking changes (#3488) 2019-11-08 13:44:52 -08:00
terminal Integrate inbox changes up to 68d3b53286dd 2019-12-02 17:24:26 -08:00
testlist inbox: Merge accumulated build fixes from RS_ONECORE_DEP_ACIOSS (#1002) 2019-05-24 12:28:30 -07:00
tools ColorTool: Proofread the helper text, update Build.bat (#2644) 2019-12-03 12:44:23 -08:00
tsf Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
types Upgrade UiaProviders to WRL::ComPtr (#3051) 2019-11-21 16:08:37 -08:00
winconpty Force the use of the static pseudoconsole functions in TConn (#3582) 2019-11-15 17:02:38 -08:00
common.build.post.props Tree-shake the library link list (#3631) 2019-11-20 09:44:23 -08:00
common.build.pre.props Replace ConhostConnection with ConptyConnection (#3461) 2019-11-06 15:09:01 -08:00
common.build.tests.props Refactor TerminalApp and Add Tests for Xaml Content (#1164) 2019-07-15 14:27:56 -05:00
ConsolePerf.regions.xml Tab to spaces (#578) 2019-05-13 18:06:36 -07:00
ConsolePerf.wprp Tab to spaces (#578) 2019-05-13 18:06:36 -07:00
cppwinrt.build.post.props Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
cppwinrt.build.pre.props Introduce a Universal package for Windows Terminal (#3236) 2019-11-25 16:30:45 -08:00
dirs Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
project.inc Sync with latest inbox changes 2019-10-17 15:11:07 -07:00
project.unittest.inc inbox: merge refactoring payload from FI 2019-06-11 17:01:26 -07:00
StaticAnalysis.ruleset Combined changes to make the build work again (see inside) (#2945) 2019-09-30 10:39:55 -07:00
unit.tests.x64.runsettings Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
unit.tests.x86.runsettings Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
wap-common.build.post.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
wap-common.build.pre.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00