Repository: microsoft/terminal (language: cpp)

Issue:
Application crashes when focusFollowMouse is enabled
### Windows Terminal version

1.18.1421.0

### Windows build number

22621.1344

### Other Software

WSL
FarManager

### Steps to reproduce

Open profile entry.

### Expected Behavior

Open screen of application.

### Actual Behavior

WindowsTermninal application aborted with error:

Faulting application name: WindowsTerminal.exe, version: 1.18.2305.22001, time stamp: 0x646c16cf
Faulting module name: ucrtbase.dll, version: 10.0.22621.608, time stamp: 0xf5fc15a3
Exception code: 0xc0000409
Fault offset: 0x000000000007f61e
Faulting process id: 0x0xEB4
Faulting application start time: 0x0x1D98DEF4ED2D0CD
Faulting application path: C:\Program Files\WindowsApps\Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe
Faulting module path: C:\WINDOWS\System32\ucrtbase.dll
Report Id: d5f35825-bb26-459f-91ef-20e1e8e5c9cc
Faulting package full name: Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe
Faulting package-relative application ID: App

--------------------------------------

Fault bucket , type 0
Event Name: MoBEX
Response: Not available
Cab Id: 0

Problem signature:
P1: Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe
P2: praid:App
P3: 1.18.2305.22001
P4: 646c16cf
P5: ucrtbase.dll
P6: 10.0.22621.608
P7: f5fc15a3
P8: 000000000007f61e
P9: c0000409
P10: 0000000000000007

Attached files:

These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_Microsoft.Window_c2d345a83ebd4f63f65431ce4b20f769d6644d_03f0cf04_e1e6e590-85ca-4740-a653-a1e60ec30e78

Analysis symbol: 
Rechecking for solution: 0
Report Id: d5f35825-bb26-459f-91ef-20e1e8e5c9cc
Report Status: 4100
Hashed bucket: 
Cab Guid: 0

---------------------------

Fault bucket 1525387907268971424, type 5
Event Name: MoBEX
Response: Not available
Cab Id: 0

Problem signature:
P1: Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe
P2: praid:App
P3: 1.18.2305.22001
P4: 646c16cf
P5: ucrtbase.dll
P6: 10.0.22621.608
P7: f5fc15a3
P8: 000000000007f61e
P9: c0000409
P10: 0000000000000007

Attached files:
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.86404f2d-8a99-494e-9315-eeb0acc11a2a.tmp.WERInternalMetadata.xml

These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_Microsoft.Window_c2d345a83ebd4f63f65431ce4b20f769d6644d_03f0cf04_e1e6e590-85ca-4740-a653-a1e60ec30e78

Analysis symbol: 
Rechecking for solution: 0
Report Id: d5f35825-bb26-459f-91ef-20e1e8e5c9cc
Report Status: 268439552
Hashed bucket: 48cb60da2fa68c80e52b443845718ba0
Cab Guid: 0


Application crashes when focusFollowMouse is enabled
### Windows Terminal version

1.18.1421.0

### Windows build number

22621.1344

### Other Software

WSL
FarManager

### Steps to reproduce

Open profile entry.

### Expected Behavior

Open screen of application.

### Actual Behavior

WindowsTermninal application aborted with error:

Faulting application name: WindowsTerminal.exe, version: 1.18.2305.22001, time stamp: 0x646c16cf
Faulting module name: ucrtbase.dll, version: 10.0.22621.608, time stamp: 0xf5fc15a3
Exception code: 0xc0000409
Fault offset: 0x000000000007f61e
Faulting process id: 0x0xEB4
Faulting application start time: 0x0x1D98DEF4ED2D0CD
Faulting application path: C:\Program Files\WindowsApps\Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe
Faulting module path: C:\WINDOWS\System32\ucrtbase.dll
Report Id: d5f35825-bb26-459f-91ef-20e1e8e5c9cc
Faulting package full name: Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe
Faulting package-relative application ID: App

--------------------------------------

Fault bucket , type 0
Event Name: MoBEX
Response: Not available
Cab Id: 0

Problem signature:
P1: Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe
P2: praid:App
P3: 1.18.2305.22001
P4: 646c16cf
P5: ucrtbase.dll
P6: 10.0.22621.608
P7: f5fc15a3
P8: 000000000007f61e
P9: c0000409
P10: 0000000000000007

Attached files:

These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_Microsoft.Window_c2d345a83ebd4f63f65431ce4b20f769d6644d_03f0cf04_e1e6e590-85ca-4740-a653-a1e60ec30e78

Analysis symbol: 
Rechecking for solution: 0
Report Id: d5f35825-bb26-459f-91ef-20e1e8e5c9cc
Report Status: 4100
Hashed bucket: 
Cab Guid: 0

---------------------------

Fault bucket 1525387907268971424, type 5
Event Name: MoBEX
Response: Not available
Cab Id: 0

Problem signature:
P1: Microsoft.WindowsTerminalPreview_1.18.1421.0_x64__8wekyb3d8bbwe
P2: praid:App
P3: 1.18.2305.22001
P4: 646c16cf
P5: ucrtbase.dll
P6: 10.0.22621.608
P7: f5fc15a3
P8: 000000000007f61e
P9: c0000409
P10: 0000000000000007

Attached files:
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.86404f2d-8a99-494e-9315-eeb0acc11a2a.tmp.WERInternalMetadata.xml

These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_Microsoft.Window_c2d345a83ebd4f63f65431ce4b20f769d6644d_03f0cf04_e1e6e590-85ca-4740-a653-a1e60ec30e78

Analysis symbol: 
Rechecking for solution: 0
Report Id: d5f35825-bb26-459f-91ef-20e1e8e5c9cc
Report Status: 268439552
Hashed bucket: 48cb60da2fa68c80e52b443845718ba0
Cab Guid: 0




Discussion / hints:
`BucketDetails?BucketIdentifier=48cb60da-2fa6-8c80-e52b-443845718ba0` seems to have... two different failures in it? 

* The first was from a test machine, so I'm not sure how real that is
* `Failure?FailureSearchText=99935d8e-2b64-88fd-6c7d-2215bf2e8270` is `FAIL_FAST_FATAL_APP_EXIT_c0000409_TerminalApp.dll!winrt::Windows::Foundation::IUnknown::try_as_winrt::Microsoft::Terminal::Control::TermControl_`
  * There's only a couple cabs here... maybe not enough to work with?
  * Filed as MSFT:44764490
  
  
Looks like the crash is attributed to L959 here:
https://github.com/microsoft/terminal/blob/c589784b54d46187289651fa6c04c49fe05826aa/src/cascadia/TerminalApp/TerminalTab.cpp#L953-L965

Do you happen to have [`focusFollowMouse`](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/interaction#automatically-focus-pane-on-mouse-hover) enabled?

I suppose just looking at that code, we're taking the parameter by reference, which is bad for a coroutine. I don't really think this should have regressed in 1.18. Maybe there's another root cause hiding. I'll trawl through more dumps. 
You right.
For "focusFollowMouse" was by set value to "true".
With set to "false" error does not replicable.
Well that's really helpful! If turning that off fixes this, then surely that must be the real source of this bug. That's something we can fix easily enough. 
`BucketDetails?BucketIdentifier=48cb60da-2fa6-8c80-e52b-443845718ba0` seems to have... two different failures in it? 

* The first was from a test machine, so I'm not sure how real that is
* `Failure?FailureSearchText=99935d8e-2b64-88fd-6c7d-2215bf2e8270` is `FAIL_FAST_FATAL_APP_EXIT_c0000409_TerminalApp.dll!winrt::Windows::Foundation::IUnknown::try_as_winrt::Microsoft::Terminal::Control::TermControl_`
  * There's only a couple cabs here... maybe not enough to work with?
  * Filed as MSFT:44764490
  
  
Looks like the crash is attributed to L959 here:
https://github.com/microsoft/terminal/blob/c589784b54d46187289651fa6c04c49fe05826aa/src/cascadia/TerminalApp/TerminalTab.cpp#L953-L965

Do you happen to have [`focusFollowMouse`](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/interaction#automatically-focus-pane-on-mouse-hover) enabled?

I suppose just looking at that code, we're taking the parameter by reference, which is bad for a coroutine. I don't really think this should have regressed in 1.18. Maybe there's another root cause hiding. I'll trawl through more dumps. 
You right.
For "focusFollowMouse" was by set value to "true".
With set to "false" error does not replicable.
Well that's really helpful! If turning that off fixes this, then surely that must be the real source of this bug. That's something we can fix easily enough. 

Fix patch:
diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp
index 28f9152794b..5a5bfb65f03 100644
--- a/src/cascadia/TerminalApp/TerminalTab.cpp
+++ b/src/cascadia/TerminalApp/TerminalTab.cpp
@@ -950,7 +950,7 @@ namespace winrt::TerminalApp::implementation
             }
         });
 
-        events.focusToken = control.FocusFollowMouseRequested([dispatcher, weakThis](auto&& sender, auto&&) -> winrt::fire_and_forget {
+        events.focusToken = control.FocusFollowMouseRequested([dispatcher, weakThis](auto sender, auto) -> winrt::fire_and_forget {
             co_await wil::resume_foreground(dispatcher);
             if (const auto tab{ weakThis.get() })
             {


Test patch: