https://kotlinlang.org logo
#korge
Title
# korge
p

Pablo Caviglia

11/05/2020, 4:53 PM
hi all, does someone knows why this happens and how can it be fixed? kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@2fbf0c8 at kfun:kotlin.Throwable.<init>(kotlin.String?;kotlin.Throwable?)kotlin.Throwable (00000000007e0e00) at ThrowInvalidMutabilityException (00000000004c8d50) at kfun:kotlin.collections.HashMap.<set-length>#internal (00000000007ea080) at kfun:kotlin.collections.HashMap.addKey$stdlib(K)kotlin.Int (00000000007eaea0) at kfun:kotlin.collections.HashMap.put(K;V)V? (00000000007ec770) at kfun:com.senaptec.toolframework.util.FontLoader.$loadCOROUTINE$108.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? (0000000000560d10)
is it because it's an object?
message has been deleted
n

Nico

11/05/2020, 4:55 PM
Is this on Mac target ?
p

Pablo Caviglia

11/05/2020, 4:55 PM
mac and mingw
c

Casey Brooks

11/05/2020, 4:55 PM
Most likely, yes. Objects and all other top-level constructs are frozen on creation, as are all its properties. Even though its a MutableMap, that map is still frozen and can’t be edited
p

Pablo Caviglia

11/05/2020, 4:55 PM
s*it
ok, what about create a singleton with companion ?
should that work fine ?
c

Casey Brooks

11/05/2020, 4:57 PM
Nope, companion objects are still considered top-level. Super annoying, I know. You will have to use one of the atomics from the Stately lib to do any modification on singletons https://github.com/touchlab/Stately
p

Pablo Caviglia

11/05/2020, 4:57 PM
🤦‍♂️
i just want to have a global var to store references to fonts
or to whatever
c

Casey Brooks

11/05/2020, 5:00 PM
Yeah I know, it drives me crazy. The alternative is to make it a local object and use DI to it where you need it. Korge has an injector module which could probably make this a bit less painful
p

Pablo Caviglia

11/05/2020, 5:00 PM
uhmm, good idea
c

Casey Brooks

11/05/2020, 5:00 PM
p

Pablo Caviglia

11/05/2020, 5:00 PM
what about korge 2 with its new kotlin mp version?
solved in there?
c

Casey Brooks

11/05/2020, 5:01 PM
I haven’t tried 2.0 yet. But it’s not a limititation of korge, it’s a fundamental restriction from Kotlin Native. No way around it other than using atomics or not using global objects
p

Pablo Caviglia

11/05/2020, 5:04 PM
ok, will go with DI, in fact i like the idea of using DI in the project from an architecture point of view
is there any doc apart from this page regardin korinject? https://korlibs.soywiz.com/korinject/
c

Casey Brooks

11/05/2020, 5:23 PM
This video tutorial touches briefly on it, but I’m not aware of any other docs

https://youtu.be/pdUEQP1Ry08?t=360

p

Pablo Caviglia

11/05/2020, 5:24 PM
thx man, watching now
works like a charm with mapSingleton
👍 thx man
🙇‍♂️ 1
2 Views