Thread
#multiplatform
    m

    Marko Novakovic

    6 months ago
    iOS crash
    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)
    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

    Rick Clephas

    6 months ago
    Are you by any chance using other libraries that also depend on kotlinx.coroutines?
    m

    Marko Novakovic

    6 months ago
    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

    Rick Clephas

    6 months ago
    Could you try and see if using
    CoroutineScope(SupervisorJob() + Dispatchers.Default)
    instead of
    MainScope()
    makes a difference?
    m

    Marko Novakovic

    6 months ago
    I will try it now
    thanks
    illegal attempt to access non-shared <object>@2cc6128 from other thread
    actually it’s not your library that causes errors
    r

    Rick Clephas

    6 months ago
    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

    Marko Novakovic

    6 months ago
    solved it 😄
    kotlin.native.binary.memoryModel=experimental
    forgot to add this in
    gradle.properties