iOS crash ```Uncaught Kotlin exception: kotlin.Ill...
# multiplatform
m
iOS crash
Copy code
Uncaught Kotlin exception: kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
Kotlin 1.6.10 and 0.11.3-new-mm https://github.com/rickclephas/KMP-NativeCoroutines (idk if this library has anything to do with it tho)
Copy code
class Count {

    @NativeCoroutineScope
    private val coroutineScope = MainScope()

    private val _count = MutableStateFlow(0)
    val count: StateFlow<Int>
        get() = _count.asStateFlow()

    init {
        coroutineScope.launch {
            _count.value = 1
            delay(500)
            _count.value = 2
            delay(500)
            _count.value = 3
            delay(500)
            _count.value = 4
            delay(500)
            _count.value = 5
        }
    }
}
r
Are you by any chance using other libraries that also depend on kotlinx.coroutines?
m
no. I tried adding NativeCoroutines to existing project and I was facing issues so I created sample project where am just using your library and I get this problem
am on M1 mac if that info helps in any way
r
Could you try and see if using
CoroutineScope(SupervisorJob() + Dispatchers.Default)
instead of
MainScope()
makes a difference?
m
I will try it now
thanks
Copy code
illegal attempt to access non-shared <object>@2cc6128 from other thread
actually it’s not your library that causes errors
r
Alright that error sounds better 🙂. You should either annotate the object with
SharedImmutable
or
ThreadLocal
. https://kotlinlang.org/docs/native-immutability.html#global-variables-and-singletons
m
solved it 😄
👍🏻 1
Copy code
kotlin.native.binary.memoryModel=experimental
forgot to add this in
gradle.properties