I have an odd crash in release mode only. Followin...
# multiplatform
c
I have an odd crash in release mode only. Following code crashes with bad access 0x0 when accessing the
by lazy
part:
Copy code
val preferences by lazy { SharedBaseInjector.get().preferences } // Crash in this line

fun something() {
    SharedBaseInjector.get().preferences  // This is fine
    val x = preferences.someValue
    ....
}
In debug mode everything is fine. If I wrap the preferences variable in an object it’s also fine in release mode:
Copy code
private object Cache {
val preferences by lazy { SharedBaseInjector.get().preferences }
}

fun something() {
    val x = Cache.preferences.someValue
    ....
}
Anyone having a clue what’s going on? The object fixes it for me…but I’d still like to understand what’s going on
h
Crash on iOS when get into shared module?
c
On iOS when it calls
by lazy
Android is working fine
h
@Christian Würthenr, I have encountered the similar issue before, android works fine but iOS keep crashing. It’s caused by different initialisation timing between kotlin and swift when you use
lazy
. You can give a try without
lazy
, directly use getter/setter function.