I recently switched my Kotlin Multiplatform Android coroutines library from org.jetbrains.kotlinx:ko...
r
I recently switched my Kotlin Multiplatform Android coroutines library from org.jetbrains.kotlinxkotlinx coroutines core1.5.2-native-mt to 1.6.0 which I thought solved the threading issues in 1.5.x. However, now my iOS app, which consumes the Multiplatform library, is crashing on the first occurrence of a coroutine being launched (stack trace below). The code causing the crash is below. What is a resolution to this issue?
Copy code
// in Kotlin Multiplatform library
DeviceSource {
    override fun start() {
        testDevices
            .onEach { list ->
                list.devices.forEach { addKnownDevice(it) }
            }
            .launchIn(Dispatchers.Main)
    }
Exception:
Copy code
at 0   test                            0x10c51f388        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 88 
  at 1   test                            0x10c519286        kfun:kotlin.Exception#<init>(kotlin.String?){} + 86 
  at 2   test                            0x10c519476        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 86 
  at 3   test                            0x10c5199c6        kfun:kotlin.IllegalStateException#<init>(kotlin.String?){} + 86 
  at 4   test                            0x10c6aab54        kfun:kotlinx.coroutines.takeEventLoop#internal + 388 
  at 5   test                            0x10c6aad03        kfun:kotlinx.coroutines.OldDefaultExecutor#dispatch(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.Runnable){} + 179 
  at 6   test                            0x10c6ab211        kfun:kotlinx.coroutines.OldMainDispatcher#dispatch(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.Runnable){} + 241 
  at 7   test                            0x10c68e783        kfun:kotlinx.coroutines.internal#resumeCancellableWith__at__kotlin.coroutines.Continuation<0:0>(kotlin.Result<0:0>;kotlin.Function1<kotlin.Throwable,kotlin.Unit>?){0§<kotlin.Any?>} + 1091 
  at 8   test                            0x10c69e37b        kfun:kotlinx.coroutines.intrinsics#startCoroutineCancellable__at__kotlin.coroutines.SuspendFunction1<0:0,0:1>(0:0;kotlin.coroutines.Continuation<0:1>;kotlin.Function1<kotlin.Throwable,kotlin.Unit>?){0§<kotlin.Any?>;1§<kotlin.Any?>} + 603 
  at 9   test                            0x10c69e57d        kfun:kotlinx.coroutines.intrinsics#startCoroutineCancellable$default__at__kotlin.coroutines.SuspendFunction1<0:0,0:1>(0:0;kotlin.coroutines.Continuation<0:1>;kotlin.Function1<kotlin.Throwable,kotlin.Unit>?;kotlin.Int){0§<kotlin.Any?>;1§<kotlin.Any?>} + 333 
  at 10  test                            0x10c624883        kfun:kotlinx.coroutines.CoroutineStart#invoke(kotlin.coroutines.SuspendFunction1<0:0,0:1>;0:0;kotlin.coroutines.Continuation<0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>} + 323 
  at 11  test                            0x10c613edc        kfun:kotlinx.coroutines.AbstractCoroutine#start(kotlinx.coroutines.CoroutineStart;0:0;kotlin.coroutines.SuspendFunction1<0:0,1:0>){0§<kotlin.Any?>} + 156 
  at 12  test                            0x10c614139        kfun:kotlinx.coroutines#launch__at__kotlinx.coroutines.CoroutineScope(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.CoroutineStart;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>){}kotlinx.coroutines.Job + 585 
  at 13  test                            0x10c614452        kfun:kotlinx.coroutines#launch$default__at__kotlinx.coroutines.CoroutineScope(kotlin.coroutines.CoroutineContext?;kotlinx.coroutines.CoroutineStart?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>;kotlin.Int){}kotlinx.coroutines.Job + 626 
  at 14  test                            0x10c688823        kfun:kotlinx.coroutines.flow#launchIn__at__kotlinx.coroutines.flow.Flow<0:0>(kotlinx.coroutines.CoroutineScope){0§<kotlin.Any?>}kotlinx.coroutines.Job + 275 
  at 15  test                            0x10c45672b        kfun:com.testlabs.testshared.device.DeviceSourceImpl#start(){} + 539 
  at 16  test                            0x10c4e206b        objc2kotlin.1302 + 139 
  at 17  test                            0x10c2940cf        $s8test19MultiplatformConfigO5startyyFZ + 95 (/Users/rachelcarandang/dev/test/Config/MultiplatformConfig.swift:48:42)
  at 18  test                            0x10c0999ff        $s8test9AppConfigO5startyyFZ + 47 (/Users/rachelcarandang/dev/test/Config/AppConfig.swift:46:29)
  at 19  test                            0x10c2c5941        $s8test11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF + 1057 (/Users/rachelcarandang/dev/test/test/AppDelegate.swift:40:19)
  at 20  test                            0x10c2c6096        $s8test11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtFTo + 182 
  at 21  UIKitCore                           0x7fff25055f2e     -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 215 
  at 22  UIKitCore                           0x7fff25057b9e     -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4114 
  at 23  UIKitCore                           0x7fff2505d50d     -[UIApplication _runWithMainScene:transitionContext:completion:] + 1220 
  at 24  UIKitCore                           0x7fff245d9c79     -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 121
m
Did you enable the new native memory model? That is required to use the non multithreaded variant of coroutines on native.
r
Thanks! I’ll try that
I missed that config
a
Hello Rachel, I am glad you got the help you were seeking. How ever, it would be great if next time you paste your error logs in the thread to avoid clogging the channel's posts
r
Okay, will do!