What does this function `RUNTIME_NOTHROW void Kotl...
# kotlin-native
z
What does this function
RUNTIME_NOTHROW void Kotlin_initRuntimeIfNeeded()
do? This function is in
kotlin/kotlin-native/runtime/src/main/cpp/Runtime.cpp
. 1. I found it got called all the time when trying to run my iOSApp, then I got a runtime exception when it ran into
InitOrDeinitGlobalVariables(INIT_GLOBALS, result->memoryState);
. It looks like the runtime environment had not fully created at that point, and it has already called OC bridge function, then caused an exception. 2. I also found another problem when using k/n. Top-level properties declared in kotlin will always return null when running iOSApp. I made it a top-level function and it worked. This problem also happened when KN was running into
Kotlin_initRuntimeIfNeeded()
. 3. btw, debug shared.framework and k/n lib with disasm showed in lldb is tough. Is there any way to debug k/n from source when running iOSApp? Does anyone has any idea here?
j
Is this with the new memory model or old?
z
kotlin version is 1.5.31
j
So what
initRuntimeIfNeeded
does is just to actually start/init the called library on the current thread if it already is not. So it is a way to make sure you can access certain runtimes when doing threaded work
If you want to debug with xcode and not intellij https://github.com/touchlab/xcode-kotlin has some integration for that
z
Thx, is there any way to track code into jetbrain’s K/N source code when debugging iOSApp?
j
blob big smile 1
n
I think 2. could be fixed if you use 1.6.0 or higher, top level properties initialization logic was changed. 1. might be a bug, but I'd also try with latest Kotlin version before filing an issue.
đź‘Ť 1
z
Well, 2 was first found when using Kotlin 1.6.0 :-), I also tried 1.6.20-dev5891 and 1.5.31, it also happened