JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.95k stars 1.16k forks source link

`LazyListState.scrollToItem` causes a crash if it called on the start (aosp) #1540

Open igordmn opened 2 years ago

igordmn commented 2 years ago

androidx-main 821c6c51 (aosp). Doesn't crash in Compose MPP 1.0.0

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Text
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.window.singleWindowApplication

fun main() = singleWindowApplication {
    val state = rememberLazyListState()

    LazyColumn(state = state) {
        items(100) {
            Text("item")
        }
    }

    LaunchedEffect(Unit) {
        state.scrollToItem(50)
    }
}

Crash:


Exception in thread "AWT-EventQueue-0 @coroutine#9" java.lang.IllegalStateException: measure() may not be called multiple times on the same Measurable
    at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:86)
    at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui(LayoutNode.kt:1302)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure(MeasureAndLayoutDelegate.kt:172)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:232)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:38)
    at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:205)
    at androidx.compose.ui.platform.SkiaBasedOwner.measureAndLayout(SkiaBasedOwner.skiko.kt:275)
    at androidx.compose.ui.node.Owner$DefaultImpls.measureAndLayout$default(Owner.kt:182)
    at androidx.compose.ui.ComposeScene.getContentSize-YbymL2g(ComposeScene.skiko.kt:300)
    at androidx.compose.ui.awt.ComposeLayer$ComponentImpl.doLayout(ComposeLayer.desktop.kt:111)
    at java.desktop/java.awt.Container.validateTree(Container.java:1722)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validateTree(Container.java:1731)
    at java.desktop/java.awt.Container.validate(Container.java:1657)
    at java.desktop/java.awt.Container.validateUnconditionally(Container.java:1694)
    at java.desktop/java.awt.Window.show(Window.java:1050)
    at java.desktop/java.awt.Component.show(Component.java:1716)
    at java.desktop/java.awt.Component.setVisible(Component.java:1663)
    at java.desktop/java.awt.Window.setVisible(Window.java:1031)
    at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$4$1.invokeSuspend(AwtWindow.desktop.kt:122)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
okushnikov commented 3 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.