Closed jimgoog closed 3 years ago
Thanks!
It crashes on Windows too
the code does not crash on Mac.
It is because of the different Font metrics.
This code crashes on Android too:
val state = remember { derivedStateOf { 1 } } // derivedStateOf is used in Modifier.indication
Canvas(Modifier.size(20.dp)) {
// reading derivedStateOf implicitly forces Snapshot.sendApplyNotifications(),
// and so requestRelayout
state.value
}
BasicTextField(
TextFieldValue("text"),
{},
textStyle = TextStyle(fontSize = 100.sp, textIndent = TextIndent(firstLine = 10.sp)),
modifier = Modifier.requiredSize(20.dp)
)
Inside BasicTextField
we change mutableStateOf during layout stage, by this we schedule applying state snapshot. During the draw stage we force applying snapshot, and so mark all changed nodes as NeedsRelayout
.
More simple reproducer:
var b by mutableStateOf(0)
fun main() = Window {
val state = derivedStateOf { 1 }
Canvas(Modifier.size(20.dp)) {
println("DRAW")
state.value
}
Box {
Box {
b
}
Layout({}, measurePolicy = { _, _ ->
layout(10, 10) {
println("LAYOUT")
b++
}
})
}
}
What we can do:
mutableStateOf
on layout stage (inside Modifier.textFieldScroll
)derivedStateOf
(don't know how we can achieve this, we need to investigate how we can keep derivedStateOf
fresh without applying snapshot)P.S. BTW, maybe in the future we should prohibit requestRemeasure
/requestRelayout
/changing mutableStateOf
during recomposition/layout/draw? There are a lot of bugs regarding them.
@jimgoog looks like pretty generic issue to be considered on all Compose platforms.
Filled https://issuetracker.google.com/issues/182821580. Igor, thanks for the investigation
FYI this assertion was removed https://android-review.googlesource.com/c/platform/frameworks/support/+/1640305/
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
The following code throws an exception on Linux when the user clicks the button:
Interestingly, the code does not crash on Mac.
The exception thrown on Linux is:
cc @igordmn