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

Ben Trengrove [G]

04/20/2022, 9:53 PM
For the LazyLayout crash, do you have a sample that reproduces it or is it just happening in your app?
a

andrew

04/20/2022, 10:11 PM
It happens on all of my targets so far, consistently
Lemme throw together a quick sample using @Preview
b

Ben Trengrove [G]

04/20/2022, 10:12 PM
Thank you, that would be great
a

andrew

04/20/2022, 10:13 PM
No problem
Got it, doesnt happen for simpler layouts
Copy code
data class ItemHolder(val value: Int)
val items = List(1000) { ItemHolder(it) }

@Composable
@Preview
fun LazyCrashReproduction() {
    LazyColumn {
        items(items, key = { it.value.toString() }) { item ->
            val modifier = Modifier.clickable { println(item) }

            Item(item, modifier)
        }
    }
}

@Composable
fun Icon(
    @DrawableRes icon: Int,
    modifier: Modifier = Modifier,
) {
    if (icon == -1) return Box(modifier.size(24.dp))

    val painter = painterResource(icon)

    BoxWithConstraints(modifier, Alignment.Center) {
        Box(modifier = Modifier.size(24.dp).paint(
            painter = painter,
            colorFilter = ColorFilter.tint(Color.Black.copy(alpha = 1F)),
            contentScale = ContentScale.Fit,
        ))
    }
}

@Composable
fun Item(item: ItemHolder, modifier: Modifier = Modifier) {
    Row(Modifier.height(48.dp).fillMaxWidth().then(modifier).padding(16.dp)) {
        Icon(android.R.drawable.ic_input_add)
        BasicText(item.value.toString(), style = TextStyle.Default.copy(Color.Green))
    }
}
This should trigger it, this is as stripped down as I can get it, as soon as this Icon component is added in, it flips
It looks like BoxWithConstraints is what causes it
Copy code
2022-04-20 18:49:26.742 7762-7762/com.stratisiot.mobile E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.stratisiot.mobile, PID: 7762
    java.lang.IllegalArgumentException: Inconsistency between the count of nodes tracked by the state (0) and the children count on the SubcomposeLayout (1). Are you trying to use the state of the disposed SubcomposeLayout?
        at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.makeSureStateIsConsistent(SubcomposeLayout.kt:514)
        at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:391)
        at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$Scope.subcompose(SubcomposeLayout.kt:715)
        at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke-0kLqBqw(BoxWithConstraints.kt:69)
        at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke(BoxWithConstraints.kt:67)
        at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:581)
        at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:44)
        at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1388)
        at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1387)
        at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2063)
        at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:112)
        at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:78)
        at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:66)
        at androidx.compose.ui.node.LayoutNode.performMeasure-BRTryo0$ui_release(LayoutNode.kt:1387)
        at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
        at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1341)
        at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release$default(LayoutNode.kt:1337)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:187)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:274)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:38)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:208)
        at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout(AndroidComposeView.android.kt:740)
        at androidx.compose.ui.node.Owner$DefaultImpls.measureAndLayout$default(Owner.kt:196)
        at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.android.kt:937)
        at android.view.View.draw(View.java:22353)
        at android.view.View.updateDisplayListIfDirty(View.java:21226)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4500)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4473)
        at android.view.View.updateDisplayListIfDirty(View.java:21186)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:559)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:565)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:642)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:4101)
2022-04-20 18:49:26.742 7762-7762/com.stratisiot.mobile E/AndroidRuntime:     at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3828)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3099)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
        at android.view.Choreographer.doCallbacks(Choreographer.java:796)
        at android.view.Choreographer.doFrame(Choreographer.java:731)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Perhaps it’s nested `SubcomposeLayout`s?
Actually, if it were nested
SubcomposeLayout
then it would just straight up crash… y’all would know better than I 🙂
As soon as I remove the BoxWithConstraints, it fixes it
a

Andrey Kulikov

04/20/2022, 10:59 PM
please file a bug with the sample you shared, just to track it easier. we will try to fix it for the next release
a

andrew

04/20/2022, 11:00 PM
Sounds good, does:
Android Public Tracker > App Development > Jetpack Compose > UI Libraries > Foundation
work for organization?
b

Ben Trengrove [G]

04/20/2022, 11:02 PM
a

andrew

04/20/2022, 11:02 PM
coolbeans
b

Ben Trengrove [G]

04/20/2022, 11:02 PM
Thanks for all your help!
a

Andrey Kulikov

04/20/2022, 11:02 PM
Foundation works as well, it will be triaged there 🙂
a

andrew

04/20/2022, 11:10 PM
Created: https://issuetracker.google.com/issues/229752147 Thanks for the quick response, as always. I love how responsive the team is here!
🙏 5
5 Views