AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.14k stars 2.26k forks source link

Uncaught exception when keyboard input source is Japanese and Live Conversion is on #17341

Open jeromemanzano opened 1 month ago

jeromemanzano commented 1 month ago

Describe the bug

When typing in TextBox with keyboard input source set to Japanese - Kana and Live Conversion is on, the NSExceptionHandler captures this uncaught exception:

NSExceptionHandler has recorded the following exception:
NSRangeException -- NSConcreteMutableAttributedString attributedSubstringFromRange:: Out of bounds
Stack trace: 
SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) (in HIToolbox) + 356
SendEventToEventTargetWithOptions (in HIToolbox) + 44
SendTSMEvent_WithCompletionHandler (in HIToolbox) + 432
__SendTextInputEvent_WithCompletionHandler_block_invoke (in HIToolbox) + 568
SendTextInputEvent_WithCompletionHandler (in HIToolbox) + 1064
-[IMKInputSession _postEvent:completionHandler:] (in HIToolbox) + 176
-[IMKInputSession _createAndSendOffsetToPointEvent:completionHandler:] (in HIToolbox) + 344
-[IMKInputSession attributesForCharacterIndex_andLineRect:completionHandler:] (in HIToolbox) + 476
-[IMKInputSession attributesForCharacterIndex:completionHandler:] (in HIToolbox) + 96
__60-[IMKInputSession imkxpc_attributesForCharacterIndex:reply:]_block_invoke (in HIToolbox) + 432
__87+[IMKInputSession IMKXPCPerformBlockOnMainThreadInMode:performHow:callerCmd:workBlock:]_block_invoke (in HIToolbox) + 128
__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ (in CoreFoundation) + 28
__CFRunLoopDoBlocks (in CoreFoundation) + 356
__CFRunLoopRun (in CoreFoundation) + 2440
CFRunLoopRunSpecific (in CoreFoundation) + 608
RunCurrentEventLoopInMode (in HIToolbox) + 292
ReceiveNextEventCommon (in HIToolbox) + 648
_BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox) + 76
_DPSNextEvent (in AppKit) + 660
-[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] (in AppKit) + 700
-[NSApplication run] (in AppKit) + 476
PlatformThreadingInterface::RunLoop(IAvnLoopCancellation*) (in libAvaloniaNative.dylib) + 564
0x10c220570
0x10c21ff44
0x10c21fa04
0x10c21f4e4
0x10c21ecac
0x10c0012a8
0x106e12084
0x106dfcec8
CallDescrWorkerInternal (in libcoreclr.dylib) + 132
MethodDescCallSite::CallTargetWorker(unsigned long long const*, unsigned long long*, int) (in libcoreclr.dylib) + 856
RunMain(MethodDesc*, short, int*, PtrArray**) (in libcoreclr.dylib) + 632
Assembly::ExecuteMainMethod(PtrArray**, int) (in libcoreclr.dylib) + 260
CorHost2::ExecuteAssembly(unsigned int, char16_t const*, int, char16_t const**, unsigned int*) (in libcoreclr.dylib) + 732
coreclr_execute_assembly (in libcoreclr.dylib) + 204
mono_jit_exec (in UncaughtExceptionTest) (coreclr-bridge.m:768)
xamarin_main (in UncaughtExceptionTest) (monotouch-main.m:495)
main (in UncaughtExceptionTest) (main.arm64.mm:66)
start (in dyld) + 2476

To Reproduce

  1. Run the sample application UncaughtExceptionTest.zip
  2. Change keyboard input source to Japanese - Kana and make sure Live Converstion is checked image
  3. In the application when you continuously type in the TextBox, you'll eventually see uncaught exception captured in the console. The exception only contains call stack addresses, but you can use atos to convert it into a symbolic stack trace.
    atos -p <process id> -l <call stack addresses>

Expected behavior

No uncaught exception thrown when typing in Japanese - Kana and Live Conversion is on

Avalonia version

11.1.4

OS

macOS

Additional context

No response