MapCompose icon indicating copy to clipboard operation
MapCompose copied to clipboard

Solved: Very large Marker size is causing crash

Open cwsiteplan opened this issue 1 year ago • 5 comments

Hi,

I ran into an issue where a marker with large dimensions is causing a crash.

 java.lang.IllegalArgumentException: Can't represent a width of 36818 and height of 36818 in Constraints
                                                                                                    	at androidx.compose.ui.unit.Constraints$Companion.createConstraints-Zbe2FdA$ui_unit_release(Constraints.kt:369)
                                                                                                    	at androidx.compose.ui.unit.ConstraintsKt.Constraints(Constraints.kt:433)
                                                                                                    	at androidx.compose.foundation.layout.SizeNode.getTargetConstraints-OenEA2s(Size.kt:794)
                                                                                                    	at androidx.compose.foundation.layout.SizeNode.measure-3p2s80s(Size.kt:806)
                                                                                                    	at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
                                                                                                    	at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:646)
                                                                                                    	at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:252)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:251)
                                                                                                    	at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2303)
                                                                                                    	at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:500)
                                                                                                    	at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:256)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
                                                                                                    	at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:113)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:1617)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:36)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:620)
                                                                                                    	at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1145)
                                                                                                    	at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release$default(LayoutNode.kt:1136)
                                                                                                    	at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:356)
                                                                                                    	at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:514)
                                                                                                    	at androidx.compose.ui.node.MeasureAndLayoutDelegate.onlyRemeasureIfScheduled(MeasureAndLayoutDelegate.kt:598)
                                                                                                    	at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtreeInternal(MeasureAndLayoutDelegate.kt:624)
                                                                                                    	at androidx.compose.ui.node.MeasureAndLayoutDelegate.forceMeasureTheSubtree(MeasureAndLayoutDelegate.kt:587)
                                                                                                    	at androidx.compose.ui.platform.AndroidComposeView.forceMeasureTheSubtree(AndroidComposeView.android.kt:993)
                                                                                                    	at androidx.compose.ui.node.Owner.forceMeasureTheSubtree$default(Owner.kt:239)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:632)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:596)
                                                                                                    	at ovh.plrapps.mapcompose.ui.markers.MarkerLayoutKt$MarkerLayout$2$1.invoke(MarkerLayout.kt:38)

I was using it in combination with clustering and the cluster having items quite close, so it would zoom in quite a lot. After quite some time of debugging I identified the issue. The map was configured with a high maxScale of > 5000 (in order to distinguish very close markers). The problem was that I had a GPS accuracy circle marker that computed it's size depending on accuracy and zoom level. That made the accuracy circle marker's size (which was anyways off-screen) exceeding 10000.dp and producing the above crash.

I reproduced that in the demo app here A simple coerce (size.coerceAtMost(500f)) on the marker size fixed the issue (but potentially leaves the problem to other marker usages).

I just logged the issue here for reference, in case someone is dealing with that in future. Not sure if a modification to the MarkerComposable could prevent that issue.

cwsiteplan avatar May 22 '24 11:05 cwsiteplan

Interestingly enough, I don't get the crash when I zoom-in manually. The crash only happens when I click on green clusters (at least for me). EDIT: I also get the crash by zooming manually (I just didn't zoom-in enough).

p-lr avatar May 23 '24 06:05 p-lr

It seems that we're hitting an internal limit due to how compose computes constraints. Width and height values need to hold on 32 bit at some point, which clearly cannot be the case when the scale is allowed to rocket at such high value.

p-lr avatar May 25 '24 16:05 p-lr

yep, think so too. question is if we can limit (coerce) the width/height to that size so we don't run into crashes.

cwsiteplan avatar May 29 '24 06:05 cwsiteplan

Coercing values would mean incorrect rendering by the layout. The Compose framework raises an exception, to notify that it no longer handles the input. I'm not comfortable having incorrect rendering.

p-lr avatar May 30 '24 18:05 p-lr

i see, then hopefully this issue might be an explanation to future users running into this.

cwsiteplan avatar May 31 '24 06:05 cwsiteplan