https://kotlinlang.org logo
#ktor
Title
# ktor
j

James Ward

04/14/2022, 8:14 PM
I'm trying to use ktor 2.0 for a native app and getting an error:
Copy code
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
    at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x43c461)
    at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x435e6d)
    at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x43600d)
    at kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} (0x46606d)
    at ThrowIncorrectDereferenceException (0x483fbe)
    at CheckGlobalsAccessible (0x603112)
    at kfun:io.ktor.client.engine.curl.<get-curlApi>#internal (0x8b15c7)
Seems like this has come up in the past: https://github.com/ktorio/ktor/issues/1559 https://github.com/ktorio/ktor/pull/2193 Think I should file a new issue? Is there a known workaround?
m

Mitchell Syer

04/14/2022, 8:21 PM
Ktor 2.0.0 requires the new native memory manager, there is a guide to enable it here https://github.com/JetBrains/kotlin/blob/master/kotlin-native/NEW_MM.md
j

James Ward

04/14/2022, 8:24 PM
That worked! Thank you.
👍 1
3 Views