From e0c659d4049bb728f705011c20e0e298e256a422 Mon Sep 17 00:00:00 2001 From: Uli Bubenheimer Date: Sun, 29 Dec 2024 21:17:01 -0500 Subject: [PATCH] fix: avoid Polygon crash on empty list of points Fixes #666 --- .../DraggableMarkersCollectionWithPolygonActivity.kt | 6 ++---- .../main/java/com/google/maps/android/compose/Polygon.kt | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/google/maps/android/compose/markerexamples/draggablemarkerscollectionwithpolygon/DraggableMarkersCollectionWithPolygonActivity.kt b/app/src/main/java/com/google/maps/android/compose/markerexamples/draggablemarkerscollectionwithpolygon/DraggableMarkersCollectionWithPolygonActivity.kt index 0faede4bf..268d362fa 100644 --- a/app/src/main/java/com/google/maps/android/compose/markerexamples/draggablemarkerscollectionwithpolygon/DraggableMarkersCollectionWithPolygonActivity.kt +++ b/app/src/main/java/com/google/maps/android/compose/markerexamples/draggablemarkerscollectionwithpolygon/DraggableMarkersCollectionWithPolygonActivity.kt @@ -187,9 +187,7 @@ private fun LocationMarker( private fun Polygon(markerPositionsModel: () -> List<() -> LatLng>) { val movingMarkerPositions = markerPositionsModel() - if (movingMarkerPositions.isNotEmpty()) { - val markerPositions = movingMarkerPositions.map { it() } + val markerPositions = movingMarkerPositions.map { it() } - Polygon(markerPositions) - } + Polygon(markerPositions) } diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/Polygon.kt b/maps-compose/src/main/java/com/google/maps/android/compose/Polygon.kt index 4eb4e01da..147d1833d 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/Polygon.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/Polygon.kt @@ -68,6 +68,8 @@ public fun Polygon( zIndex: Float = 0f, onClick: (Polygon) -> Unit = {} ) { + if (points.isEmpty()) return // avoid SDK crash + val mapApplier = currentComposer.applier as MapApplier? ComposeNode( factory = {