Using an `@Model` class as a parameter for a compo...
# compose
c
Using an
@Model
class as a parameter for a compose function does not seem to work right now? 🤔
l
Can you post the code causing this?
c
I resolved it, this seem to be caused by a race-condition somewhere
this should be it
Crash is resolved when i initialize
values
in my model with an empty array and fill it with something meaningful later
l
so by calling
values = currentTimestampAsArray()
in the constructor?
It’s not a race-condition at all, you were just defining a non null IntArray without providing a value in the constructor of the class. That was the problem. You can also specify it as a
lateinit
and avoid calling
currentTimestampAsArray
2 times
c
Yeah - but initializing
values
in my constructor aka
init
block should be perfectly fine, shouldn’t it?
There shouldn’t be a need to declare
values
as
lateinit
in this case since it’s never in an undefined state before my constructor finishes
l
if you were not doing this:
values = currentTimestampAsArray()
outside the
launch
that was the problem
c
But as you can see in the code i did (it wouldn’t compile if i wouldnt have)
l
So this code is crashing? It was not clear.
c
Yes, this code is crashing on runtime - sorry for the missing clarity
l
i’m pretty sure this is just a bug
there are some situations where @Model codegens the wrong code inside of init functions (and a few other corner cases). If you wouldn’t mind creating a bug with this code and tagging me, it would be much appreciated! - thanks
c
Will do - thanks!
@Leland Richardson [G] there you go: https://issuetracker.google.com/issues/144668818
👍 1
@Chuck Jazdzewski [G] @Leland Richardson [G] Thanks for the rapid fix! You guys are awesome!
l
👍 all chuck!