xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] [iOS] Crash due to unhandled Objective-C exception when long pressing with Apple pencil on Editor #15738

Open andyx48 opened 1 year ago

andyx48 commented 1 year ago

Description

Users of our app are experiencing crashes when long pressing an editor with an Apple Pencil. There is not known workaround and is affecting us very badly given the users lose all what they have been typing when this happens given we are not able to catch the exception.

I'm able to reproduce this all the times and on a brand new project.

Assertion failure in void __NSTextContentStorageCacheElementIndexRange(NSTextContentStorage , NSRange, const NSTextElement , NSInteger)(), NSTextContentManager.m:707 2023-05-10 10:53:01.037 CrashReproduction.iOS[823:139035] Xamarin.iOS: Aborting due to unhandled Objective-C exception: NSTextContentStorage: Inconsistent element cache state. Elements for range {0, 4} are already cached while trying to insert

================================================================= Native Crash Reporting

Got a abrt while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.

================================================================= Native stacktrace:

0x106d74c68 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x106d6b660 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x106d741b0 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x202c6d274 - /usr/lib/system/libsystem_platform.dylib : <redacted>
0x202d09118 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
0x1ab34e178 - /usr/lib/system/libsystem_c.dylib : abort
0x106efae98 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : xamarin_get_block_descriptor
0x106f00cd4 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : xamarin_release_block_on_main_thread
0x106ee2fd4 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : xamarin_UIApplicationMain
0x1049af8b8 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x1041c03dc - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x1041c0610 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x102dd19d0 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x103678480 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x106d7b9dc - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : mono_pmip
0x106e28318 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : mono_pmip
0x106e2d58c - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : mono_pmip
0x106d601d0 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x106f101c4 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : xamarin_get_original_working_directory_path
0x102dd18e0 - /private/var/containers/Bundle/Application/D08B2F86-8CAC-4EFB-8942-44202BF9D9E5/CrashReproduction.iOS.app/CrashReproduction.iOS : 
0x1c3320dec - /usr/lib/dyld : <redacted>

================================================================= Basic Fault Address Reporting

Memory around native instruction pointer (0x1e224f558):0x1e224f548 ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4 .......)...... 0x1e224f558 03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ...T.#...{...... 0x1e224f568 07 ed ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6 .........{..... 0x1e224f578 c0 03 5f d6 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ....#...{......

================================================================= Managed Stacktrace:

  at <unknown> <0xffffffff>
  at UIKit.UIApplication:xamarin_UIApplicationMain <0x00007>
  at UIKit.UIApplication:UIApplicationMain <0x0004b>
  at UIKit.UIApplication:Main <0x000df>
  at CrashReproduction.iOS.Application:Main <0x0007f>
  at System.Object:runtime_invoke_dynamic <0x0010f>

=================================================================

Steps to reproduce Write something on the editor and then proceed to try to select it with a long press, the editor will seem like adding extra spaces to complete the line you're writing and another following line and then will crash.

Expected behaviour The app highlights the text and doesn't crash.

Actual behaviour App crashes and data that was input previously is lost.

Basic Information Version with issue: 5.0.0.2196 - (also happens with the latest version) Last known good version: -

Environment Visual Studio for Mac version 17.5.4 build 8

Crash reproduction project CrashReproduction.zip

Reproduction Video https://github.com/xamarin/Xamarin.Forms/assets/36721479/f1a3a93f-88c6-4dd6-84e2-07ab811f38ea

andyx48 commented 1 year ago

Update: Just testing this in Maui and the crash is also happening.

jsuarezruiz commented 1 year ago

Update: Just testing this in Maui and the crash is also happening.

Did you open the issue on the Maui repo too?

tipa commented 1 year ago

This is a bug in the Apple UIKit framework and nothing Microsoft could or should fix with their .NET bindings. Best way to overcome this issue is probably to force TextKit 1, see here.