https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
i

ivan.savytskyi

03/25/2021, 1:36 PM
Hey folks, I'm trying to log exception on iOS via
throwable.stackTraceToString()
. But calling this API crashes with
ncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
exception and from stack trace of crash on iOS looks like it happens inside Throwable:
Copy code
#16	0x000000010fb50ffa in kfun:kotlin.Throwable.<init>$lambda-0#internal at /Users/teamcity/buildAgent/work/f01984a9f5203417/runtime/src/main/kotlin/kotlin/Throwable.kt:33
#17	0x000000010fb511ef in kfun:kotlin.Throwable.$<init>$lambda-0$FUNCTION_REFERENCE$119.invoke#internal at /Users/teamcity/buildAgent/work/f01984a9f5203417/runtime/src/main/kotlin/kotlin/Throwable.kt:32
#18	0x000000010fb7e907 in kfun:kotlin.native.concurrent.FreezeAwareLazyImpl.getOrInit#internal at /Users/teamcity/buildAgent/work/f01984a9f5203417/runtime/src/main/kotlin/kotlin/native/concurrent/Lazy.kt:28
#19	0x000000010fb7f0b0 in kfun:kotlin.native.concurrent.FreezeAwareLazyImpl#<get-value>(){}1:0 at /Users/teamcity/buildAgent/work/f01984a9f5203417/runtime/src/main/kotlin/kotlin/native/concurrent/Lazy.kt:55
#20	0x000000010fb4e975 in getValue [inlined] at /Users/teamcity/buildAgent/work/f01984a9f5203417/backend.native/build/stdlib/kotlin/util/Lazy.kt:44
#21	0x000000010fb4e93f in kfun:kotlin.Throwable.<get-stackTraceStrings>#internal at
Did anyone run into this as well? Also just ran quick test by doing this
val tmp = RuntimeException().getStackTrace()
it crashes as well
b

Benoît

03/25/2021, 5:46 PM
I've managed to get around this by freezing the
Throwable
before calling
stackTraceToString()
import kotlin.native.concurrent.freeze
If you are in commonMain, then you can always create an actual/expect for this
freeze()
function and just have one that does nothing for other targets
i

ivan.savytskyi

03/25/2021, 6:04 PM
agh, thx for advice....going to check
b

Benoît

03/25/2021, 6:18 PM
Let me know if that works 🙂
i

ivan.savytskyi

03/25/2021, 7:33 PM
no, not working for me 😞
b

Benoît

03/25/2021, 7:58 PM
Sorry then I don't know 😞
i

ivan.savytskyi

03/25/2021, 8:08 PM
it's super weird that this fails:
RuntimeException().freeze().printStackTrace()
2 Views