Closed chokokatana closed 7 months ago
+1. I also have a lot of such crashes, but i was not able to find a reason.
Sems like pager with Modifier.drawBehind
on page also causes this crash sometimes
The bug is elusive, tried to isolate it with the following code, but this doesn't crash despite having similar widget hierarchy as my real app:
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun BugComposeScreen(
backClick: Block,
) {
val pagerState = rememberPagerState(
initialPage = 0,
initialPageOffsetFraction = 0f
) {
4
}
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.Bottom
) {
Spacer(Modifier.height(20.dp))
Button(onClick = backClick) { Text(text = "Back") }
Spacer(Modifier.height(10.dp))
Text(text = "This is the second")
HorizontalPager(
state = pagerState,
modifier = Modifier
.fillMaxWidth()
.height(294.dp)
.background(Color.Blue),
pageSpacing = 8.dp,
) { pageIndex ->
Card(pageIndex)
}
}
}
}
@Composable
private fun Card(
index: Int,
) {
Column(
modifier = Modifier.padding(start = 34.dp, end = 34.dp)
) {
Canvas(modifier = Modifier.fillMaxSize(1f).background(Color.Black)) {
drawRect(
topLeft = Offset(
x = 0f,
y = 10f,
),
color = Color.DarkGray,
size = Size(1.dp.toPx(), 0f),
)
drawRect(
topLeft = Offset(
x = index * 100f,
y = 10f,
),
color = Color.White,
size = Size(1.dp.toPx(), index * 10f),
)
}
}
}
I don't even draw zero sized rects. It happens randomly after a fast fling or navigation transition. And it not always NaN > NaN
. Sometimes it is normal numbers.
This was from the early experimental iOS Compose. Now this happens much less often.
Hi, thanks for the report. Sadly, I fail to reproduce it.
From code analysis, it seems that topLeft
alone and/or size
have NaNs here when the crash happens. But it's hard to pinpoint the exact source of a problem without investigating a reliable repro.
And I'm not sure whether we should do early exit on NaNs in skia layer instead of throwing exception here, because it could actually mask the problem that could affect something else.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Describe the bug Implementing a graph drawing component using
Canvas.drawRect
everything was fine until at runtime some data made iOS crash the graph inside a horizontal pager being dragged horizontally.Affected platforms Select one of the platforms below:
The same code on Android works fine and does not crash.
Versions
To Reproduce Steps and/or the code snippet to reproduce the behavior:
Canvas
and draw a zero sized rectangle.Dump of runtime crash stack trace:
Expected behavior After debugging the issue and finding out that the problem is a zero sized rect, the only expected behavior would be that iOS does not crash like Android. Or if this is bad, maybe make the android version assert the input size so it can be caught earlier during development?