Hi. I’m updating an Android/iOS multiplatform project to 1.4, but I’m having a hard time understanding the changes in coroutines and concurrency.
Running a code like this:
Copy code
val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
...
scope.launch {
val something = withContext(Dispatchers.Default) { suspendCall() }
println(something)
}
Works fine in Andorid but in iOS I get:
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@3faca88 from other thread
should complete the call in the Default dispatcher and then the usages inside of the Man scope should not be a problem. Any clues 😓?
k
kpgalligan
11/11/2020, 2:45 PM
Do you have more code? This generally happens if you have an object in native code from Kotlin, then attempt to access it in another thread without freezing it.
m
max.cruz
11/16/2020, 8:59 AM
Thanks for your answer @kpgalligan and sorry for my late reply. Yes, I realized that my problem was that the suspendCall in my real code was a use-case passed to my presenter as a dependency. As the object is created in a different thread than the one that is executing it, then I got the error