JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.59k stars 1.14k forks source link

App crashes when launched on x86_64 iOS simulator after migrated to Kotlin 2.0 #4991

Closed aaalaniz closed 1 month ago

aaalaniz commented 1 month ago

Describe the bug

I have a Compose Multiplatform project that I recently migrated to Kotlin 2.0. I have a few Maestro tests that run on Maestro Cloud devices that are running an x86_64 iPhone 15 with iOS 17. Prior to migrating to Kotlin 2.0, these tests ran fine, but now they crash with the following stack trace.

Crashed Thread:        0  Dispatch queue: com.apple.main-thread
Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib            0x00007fff7017322a __pthread_kill + 10
1   libsystem_pthread.dylib           0x00007fff701ccf7b pthread_kill + 263
2   libsystem_c.dylib                 0x0000000114aa06b7 abort + 130
3   xyz.alaniz.aaron.Lightsaber       0x000000011053f59e (anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1::operator()() const + 14
4   xyz.alaniz.aaron.Lightsaber       0x000000011053f47f void (anonymous namespace)::$_0::operator()<(anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1>((anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1) + 47
5   xyz.alaniz.aaron.Lightsaber       0x000000011053f299 (anonymous namespace)::terminateWithUnhandledException(ObjHeader*) + 9
6   xyz.alaniz.aaron.Lightsaber       0x000000011053f257 (anonymous namespace)::processUnhandledException(ObjHeader*) + 55
7   xyz.alaniz.aaron.Lightsaber       0x000000011053ef59 (anonymous namespace)::TerminateHandler::kotlinHandler() + 217
8   libc++abi.dylib                   0x00000001135879c7 std::__terminate(void (*)()) + 8
9   libc++abi.dylib                   0x000000011358a204 __cxa_rethrow + 99
10  libobjc.A.dylib                   0x00000001128d9baf objc_exception_rethrow + 37
11  com.apple.CoreFoundation          0x0000000112aa8825 CFRunLoopRunSpecific + 851
12  com.apple.GraphicsServices        0x0000000117e27c8e GSEventRunModal + 139
13  com.apple.UIKitCore               0x000000012d12165a -[UIApplication _run] + 928
14  com.apple.UIKitCore               0x000000012d1262b5 UIApplicationMain + 101
15  com.apple.SwiftUI                 0x0000000120443e5d closure #1 in KitRendererCommon(_:) + 196
16  com.apple.SwiftUI                 0x0000000120443d97 runApp<A>(_:) + 148
17  com.apple.SwiftUI                 0x000000011fe06854 static App.main() + 61
18  xyz.alaniz.aaron.Lightsaber       0x000000010f7b3cae static iOSApp.$main() + 30
19  xyz.alaniz.aaron.Lightsaber       0x000000010f7b3d49 main + 9
20  dyld_sim                          0x000000011277ff21 start_sim + 10
21  dyld                              0x000000011f8db310 start + 2432

Affected platforms

Versions

To Reproduce

I have an open pull request where I am trying to debug this crash here, but essentially the steps to reproduce are to recreate what is being run in the GitHub Actions:

  1. Build the shared module: ./gradlew shared:assemble
  2. ./gradlew podInstall
  3. Build the iOS app:
xcodebuild -workspace iosApp/iosApp.xcworkspace \
  -scheme iosApp \
  -configuration Debug \
  -xcconfig iosApp/Configuration/Config.xcconfig \
  OBJROOT=iosApp/build/ios SYMROOT=iosApp/build/ios \
  -sdk iphonesimulator
  1. Run the app on an x86_64 iPhone simulator.

Expected behavior The app shouldn't crash on launch.

Additional context

I am able to run the Maestro test suite on my M1 iMac using the arm64 iPhone 15 simulator with iOS 17. This crash only appears to happen on x86, and this is the only option available on Maestro Cloud, according to the documentation.

MatkovIvan commented 1 month ago

By this stack trace (by __cxa_rethrow frame) I can only say that it was some C++ exception, but original stack trace and message is not here.

Currently I cannot even confirm that it's related to Compose. Could you please:

  1. Try to reproduce it in empty Compose app
  2. Probably it worth to open an issue to Kotlin issue tracker because the cause seems to be updating Kotlin, not Compose
aaalaniz commented 1 month ago

Thank you @MatkovIvan

After some more investigation, I discovered that the crash happens regardless of the architecture the test suite is run on. I think I found a bug with resources not being available at runtime, but it is not an X86_64 issue. I will create a new bug and close this one. Thanks!