https://kotlinlang.org logo
#compose
Title
# compose
c

Can

11/17/2019, 2:20 PM
Using an
@Model
class as a parameter for a compose function does not seem to work right now? 🤔
l

Luca Nicoletti

11/17/2019, 3:23 PM
Can you post the code causing this?
c

Can

11/17/2019, 3:41 PM
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

Luca Nicoletti

11/17/2019, 4:16 PM
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

Can

11/17/2019, 4:24 PM
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

Luca Nicoletti

11/17/2019, 5:37 PM
if you were not doing this:
values = currentTimestampAsArray()
outside the
launch
that was the problem
c

Can

11/17/2019, 5:50 PM
But as you can see in the code i did (it wouldn’t compile if i wouldnt have)
l

Luca Nicoletti

11/17/2019, 7:48 PM
So this code is crashing? It was not clear.
c

Can

11/17/2019, 9:11 PM
Yes, this code is crashing on runtime - sorry for the missing clarity
l

Leland Richardson [G]

11/18/2019, 7:27 AM
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

Can

11/18/2019, 8:08 AM
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

Leland Richardson [G]

11/19/2019, 5:28 PM
👍 all chuck!
2 Views