Repository: flutter
Issue: [macOS][Desktop]: Entering a compound character crashes Mac app
Labels: a: text input,engine,platform-mac,a: internationalization,a: desktop,has reproducible steps,P2,found in release: 3.0,found in release: 3.1,fyi-text-input,team-macos,triaged-macos

I'm working on IME support for Super Editor. At the moment, if I try to enter a `ü` in an empty paragraph, the entire Mac app crashes.

It's likely that this problem is the result of something that we're doing in Super Editor, however, I'm thinking that shouldn't be possible to completely crash the app. So something should probably be updated on the Flutter side, too.

The key presses to generate a `ü` are:
* opt+u
* u

Here's a snippet from the Mac crash report that results from this crash:

```
Process:               example [34359]
Path:                  /Volumes/VOLUME/*/example.app/Contents/MacOS/example
Identifier:            com.example.example
Version:               1.0.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        dart [34037]
Responsible:           studio [337]
User ID:               501

Date/Time:             2022-05-24 21:18:59.972 -0700
OS Version:            Mac OS X 10.15.7 (19H2)
Report Version:        12
Anonymous UUID:        C5B17288-D61C-4382-BD67-FC86E3BE1127

Sleep/Wake UUID:       479A5C8C-4B0D-4CEB-8B91-CB1EFC61309E

Time Awake Since Boot: 290000 seconds
Time Since Wake:       37000 seconds

System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff6e34c33a __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff6e408e60 pthread_kill + 430
2   libsystem_c.dylib             	0x00007fff6e2d3808 abort + 120
3   io.flutter.flutter-macos      	0x0000000105036e69 std::__1::__basic_string_common<true>::__throw_out_of_range() const + 9
4   io.flutter.flutter-macos      	0x0000000105cf1858 flutter::TextInputModel::AddText(std::__1::basic_string<char16_t, std::__1::char_traits<char16_t>, std::__1::allocator<char16_t> > const&) + 1384
5   io.flutter.flutter-macos      	0x0000000105cf18ac flutter::TextInputModel::AddText(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 76
6   io.flutter.flutter-macos      	0x00000001050014f9 -[FlutterTextInputPlugin insertText:replacementRange:] + 585
7   com.apple.AppKit              	0x00007fff322ac1be -[NSTextInputContext(NSInputContext_WithCompletion) insertText:replacementRange:completionHandler:] + 184
8   com.apple.AppKit              	0x00007fff32a092a2 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2.328 + 102
9   com.apple.AppKit              	0x00007fff322ac0fb -[NSTextInputContext do_HandleTSMEvent_insertFixLenTextLoop:whileCondition:dispatchWorkEach:afterEachInsertText:continuation:] + 105
10  com.apple.AppKit              	0x00007fff322abfc2 -[NSTextInputContext tryHandleTSMEvent_insertFixLenText_withContext:dispatchCondition:setupForDispatch:nestedWorkaroundCondition:nestedWorkaroundDispatchWork:loopCondition:dispatchWorkEach:afterEachInsertText:continuation:] + 310
11  com.apple.AppKit              	0x00007fff32a08ba4 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke.282 + 3027
12  com.apple.AppKit              	0x00007fff322abc0c __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2 + 74
13  com.apple.AppKit              	0x00007fff322abb8f -[NSTextInputContext tryHandleTSMEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 87
14  com.apple.AppKit              	0x00007fff322ab197 -[NSTextInputContext handleTSMEvent:completionHandler:] + 1794
15  com.apple.AppKit              	0x00007fff322aaa25 _NSTSMEventHandler + 299
16  com.apple.HIToolbox           	0x00007fff339f28ff DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1254
17  com.apple.HIToolbox           	0x00007fff339f1d8d SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 329
18  com.apple.HIToolbox           	0x00007fff339f1c3d SendEventToEventTargetWithOptions + 45
19  com.apple.HIToolbox           	0x00007fff33a4e92b SendTSMEvent_WithCompletionHandler + 381
20  com.apple.HIToolbox           	0x00007fff33bfb1cf __SendUpdateActiveInputAreaForDeadKey_WithCompletionHandler_block_invoke + 1255
21  com.apple.HIToolbox           	0x00007fff33a4ec2d __SendFilterTextEvent_WithCompletionHandler_block_invoke + 182
22  com.apple.HIToolbox           	0x00007fff33a4e97a SendTSMEvent_WithCompletionHandler + 460
23  com.apple.HIToolbox           	0x00007fff33a4e781 SendFilterTextEvent_WithCompletionHandler + 225
24  com.apple.HIToolbox           	0x00007fff33bf7937 SendUpdateActiveInputAreaForDeadKey_WithCompletionHandler + 249
25  com.apple.HIToolbox           	0x00007fff33bfa630 ProcessDeadKeyInlineSession_WithCompletionHandler + 613
26  com.apple.HIToolbox           	0x00007fff33a4e0aa __utDeliverTSMEvent_WithCompletionHandler_block_invoke + 437
27  com.apple.HIToolbox           	0x00007fff33a4dec6 TSMKeyEvent_WithCompletionHandler + 644
28  com.apple.HIToolbox           	0x00007fff33a4dc27 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_4 + 250
29  com.apple.HIToolbox           	0x00007fff33a4daa6 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_3 + 257
30  com.apple.HIToolbox           	0x00007fff33a4d872 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_2 + 282
31  com.apple.HIToolbox           	0x00007fff33a4d625 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke + 274
32  com.apple.HIToolbox           	0x00007fff33a3c15d TSMProcessRawKeyEventWithOptionsAndCompletionHandler + 3403
33  com.apple.AppKit              	0x00007fff32a0cc71 __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke_3.808 + 110
34  com.apple.AppKit              	0x00007fff32a0c9c3 __204-[NSTextInputContext tryTSMProcessRawKeyEvent_orSubstitution:dispatchCondition:setupForDispatch:furtherCondition:doubleSpaceSubstitutionCondition:doubleSpaceSubstitutionWork:dispatchTSMWork:continuation:]_block_invoke.765 + 120
35  com.apple.AppKit              	0x00007fff322a94df -[NSTextInputContext tryTSMProcessRawKeyEvent_orSubstitution:dispatchCondition:setupForDispatch:furtherCondition:doubleSpaceSubstitutionCondition:doubleSpaceSubstitutionWork:dispatchTSMWork:continuation:] + 245
36  com.apple.AppKit              	0x00007fff322a8ec5 -[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:] + 1434
37  com.apple.AppKit              	0x00007fff322a88ee -[NSTextInputContext _handleEvent:allowingSyntheticEvent:] + 105
38  io.flutter.flutter-macos      	0x00000001050007c7 -[FlutterTextInputPlugin handleKeyEvent:] + 199
39  io.flutter.flutter-macos      	0x00000001050082ae -[FlutterViewController onTextInputKeyEvent:] + 46
40  io.flutter.flutter-macos      	0x0000000104ff1705 -[FlutterKeyboardManager dispatchTextEvent:] + 69
41  io.flutter.flutter-macos      	0x0000000104ff10e8 -[FlutterKeyboardManager performProcessEvent:onFinish:] + 120
42  io.flutter.flutter-macos      	0x0000000104ff0f3e -[FlutterKeyboardManager processNextEvent] + 302
43  io.flutter.flutter-macos      	0x0000000104ff0dc8 -[FlutterKeyboardManager handleEvent:] + 136
44  io.flutter.flutter-macos      	0x000000010500853e -[FlutterViewController keyDown:] + 46
45  com.apple.AppKit              	0x00007fff32293cd9 forwardMethod + 204
46  com.apple.AppKit              	0x00007fff32293cd9 forwardMethod + 204
47  com.apple.AppKit              	0x00007fff32205d5d -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6512
48  com.apple.AppKit              	0x00007fff322041c9 -[NSWindow(NSEventRouting) sendEvent:] + 349
49  com.apple.AppKit              	0x00007fff32202efe -[NSApplication(NSEvent) sendEvent:] + 2826
50  com.apple.AppKit              	0x00007fff3204f5bf -[NSApplication run] + 707
51  com.apple.AppKit              	0x00007fff32021396 NSApplicationMain + 777
52  com.example.example           	0x0000000104fa701d main + 13 (AppDelegate.swift:5)
53  libdyld.dylib                 	0x00007fff6e204cc9 start + 1
...
```