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

Luca Nicoletti

11/22/2019, 5:33 PM
I’m trying to draw a circle when the user tap on the screen. I have a
var inputPosition: Offset? by +state { null as Offset? }
I updated it inside the
PressGestureDetector
observer with:
inputPosition = Offset(position.x.value, position.y.value)
then I have a
@Composable
function that accept an
Offset?
as input and
Draw { canvas, _ -> canvas.drawCircle(pos, size.value, paint = paint) }
with that position. I’m getting the following error as soon as the user tap somewhere:
y

Yann Badoual

11/22/2019, 6:20 PM
Did you try with hardcoded position and/or paint to see which one is causing the issue?
I tested the following, it works fine:
Copy code
Container(width = 50.dp, height = 50.dp) {
    Draw { canvas, _ ->
        canvas.drawCircle(
            center = Offset(75f, 75f),
            radius = 75f,
            paint = Paint().apply {
                color = Color.Blue
            }
        )
    }
}
l

Leland Richardson [G]

11/22/2019, 6:41 PM
if you ever get this exception, it’s an indication of a bug in our runtime/compiler, not yours. In particular, this is often seen today because effects don’t fully work as advertised… they are meant to be “positional”, but right now they are unsafe to use inside of conditional logic (though this is strictly a bug)
👍 5
if you send snippets of code that happen above this, i might be able to spot the issue. But i’m guessing that somewhere you’re using a conditional that compose is handling incorrectly
this is one of the things that will be fixed when we get rid of the +
l

Luca Nicoletti

11/25/2019, 8:45 AM
Sure, will send the code over
Thanks