valentinilk / compose-shimmer

A simple shimmer library for Jetpack Compose.
https://valentinilk.github.io/compose-shimmer/
Apache License 2.0
670 stars 37 forks source link

error in UtilKt.unclippedBoundsInWindow #19

Closed Suchomel closed 1 year ago

Suchomel commented 1 year ago

I cannot reproduce it, but i have this issue in crashlytics.

Fatal Exception: java.lang.IllegalStateException: Offset is unspecified
       at androidx.compose.ui.geometry.Offset.getX-impl(Offset.java:28)
       at androidx.compose.ui.unit.IntOffsetKt.plus-Nv-tHpc(IntOffset.kt:2)
       at androidx.compose.ui.node.NodeCoordinator.toParentPosition-MK-Hz9U(NodeCoordinator.java:2)
       at androidx.compose.ui.node.NodeCoordinator.localToRoot-MK-Hz9U(NodeCoordinator.java:9)
       at androidx.compose.ui.node.NodeCoordinator.localToWindow-MK-Hz9U(NodeCoordinator.java)
       at androidx.compose.ui.layout.LayoutCoordinatesKt.positionInWindow(LayoutCoordinates.kt:2)
       at com.valentinilk.shimmer.UtilKt.unclippedBoundsInWindow(Util.kt:1)
       at com.valentinilk.shimmer.ShimmerModifier.onGloballyPositioned(ShimmerModifier.java:1)
       at androidx.compose.ui.node.BackwardsCompatNode.onGloballyPositioned(BackwardsCompatNode.java:9)
       at androidx.compose.ui.node.LayoutNode.dispatchOnPositionedCallbacks$ui_release(LayoutNode.java:10)
       at androidx.compose.ui.node.OnPositionedDispatcher.dispatchHierarchy(OnPositionedDispatcher.java:10)
       at androidx.compose.ui.node.OnPositionedDispatcher.dispatchHierarchy(OnPositionedDispatcher.java:17)
       at androidx.compose.ui.node.OnPositionedDispatcher.dispatch(OnPositionedDispatcher.java:9)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.dispatchOnPositionedCallbacks(MeasureAndLayoutDelegate.java:9)
       at androidx.compose.ui.platform.AndroidComposeView.updatePositionCacheAndDispatch(AndroidComposeView.java:5)
       at androidx.compose.ui.platform.AndroidComposeView.onLayout(AndroidComposeView.java:10)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at androidx.compose.ui.platform.AbstractComposeView.internalOnLayout$ui_release(AbstractComposeView.java:27)
       at androidx.compose.ui.platform.AbstractComposeView.onLayout(AbstractComposeView.java)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:374)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:312)
       at com.android.internal.policy.DecorView.onLayout(DecorView.java:1331)
       at android.view.View.layout(View.java:24461)
       at android.view.ViewGroup.layout(ViewGroup.java:7412)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4609)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4031)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2919)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10491)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
       at android.view.Choreographer.doCallbacks(Choreographer.java:866)
       at android.view.Choreographer.doFrame(Choreographer.java:797)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8669)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
valentinilk commented 1 year ago

Thanks! I'll investigate.

valentinilk commented 1 year ago

Bit of a strange bug, that only seems to occur on some devices. The LayoutCoordinates doesn't offer a way to check if the call to positionInWindow will fail or not. So I had to surround it with a try and catch. 🤷‍♂️

Fixed in: 1.1.1