Open sadellie opened 5 months ago
I've tried this with Compose 1.6.0, 1.6.2, and 1.6.10, also on Windows 10, and can't repeat it. I think remember()
should return the result of the calculation before proceeding, and this looks like a race condition. I don't know what's causing this. Can you try val colors = generateHueColorPalette(data.size)
, without the remember, to see what happens?
Still crashes.
fun main() {
application {
Window(
onCloseRequest = this::exitApplication,
title = "Demo app"
) {
Column {
var showBigList by remember { mutableStateOf(false) }
val data = remember(showBigList) {
List(size = if (showBigList) 100 else 5) { it.toFloat() }
}
Button(
onClick = { showBigList = !showBigList }
) {
Text("Toggle list")
}
PieChart(
values = data,
slice = {
val colors = generateHueColorPalette(data.size)
DefaultSlice(colors[it])
}
)
}
}
}
}
I also tried to move colors
out of slice
. But no success.
fun main() {
application {
Window(
onCloseRequest = this::exitApplication,
title = "Demo app"
) {
Column {
var showBigList by remember { mutableStateOf(false) }
val data = remember(showBigList) {
List(size = if (showBigList) 100 else 5) { it.toFloat() }
}
val colors = generateHueColorPalette(data.size) // Moved here
Button(
onClick = { showBigList = !showBigList }
) {
Text("Toggle list")
}
PieChart(
values = data,
slice = {
DefaultSlice(colors[it])
}
)
}
}
}
}
I am still using my workaround which is not ideal since there are few frames where slices are Color.Transparent
. They are not noticeable due to pie animation.
If I can get it to happen, maybe I can find the reason. How frequently are you pushing the Toggle List button?
Very frequently. Like, a double click type of frequently
The cause of this might be related to #71.
When rapidly changing chart data size, the app crashes. I think
generateHueColorPalette
gets called too late.Sample
Spam-click Toggle list button to reproduce:
Logs:
Info
I managed to fix this by adding nullability when getting slice color. I found no issues with this workaround:
Library version: 0.6.0 Compose: 1.6.2 (Multiplatform) Platform: Windows 10