googlemaps / android-maps-compose

Jetpack Compose composables for the Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/maps-compose
Apache License 2.0
1.16k stars 143 forks source link

Null Pointer Exception in ClusterRenderer When Continuously Updating Cluster Item Values #622

Open mohammad-firmansyah opened 2 months ago

mohammad-firmansyah commented 2 months ago

Environment details

  1. Android API 30
  2. kotlin 1.8.10
  3. maps compose 5.0.4
  4. agp 8.4
  5. compose 1.9.1

Steps to Reproduce

  1. Start with a mutable state list that is provided to the clustering composable.
  2. Continuously update the list within a while loop.
  3. Observe that the cluster changes its position as the list updates.
  4. Zoom in on the cluster until individual items are visible.
  5. Notice that a null pointer exception occurs during this process.

Related Codes

val list = remember {
          mutableStateOf(
              mutableListOf(Vehicle(
                  lat = 0.5,
                  lng = 0.5
              ),Vehicle(
                  lat = 0.8,
                  lng = 0.8
              ),Vehicle(
                  lat = 1.5,
                  lng = 1.5
              ),Vehicle(
                  lat = 0.6,
                  lng = 0.6
              ),Vehicle(
                  lat = 0.7,
                  lng = 0.5
              ),Vehicle(
                  lat = 0.10,
                  lng = 0.17
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.63,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.656,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.6116,
                  lng = 0.94
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.94
              ),Vehicle(
                  lat = 0.621,
                  lng = 0.912
              ),Vehicle(
                  lat = 0.62,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.39
              ))
          )
      }
Clustering(items = list,
                    onClusterClick = {
                        scope.launch {
                            cameraPositionState.animate(
                                CameraUpdateFactory.newLatLngZoom(it.position,20f)
                            )
                        }
                       false
                   }, clusterItemContent = {
                        InfoWindow(asset = it)
                   })
                   )
 LaunchedEffect(key1 = Unit) {
        while (true){
            list.value.first().lat = list.value.first().lat?.plus(0.1)
            delay(100)
        }
    }

Stack trace

java.lang.NullPointerException: null cannot be cast to non-null type android.view.ViewGroup
    at com.google.maps.android.compose.clustering.ComposeUiClusterRenderer.renderViewToBitmapDescriptor(ClusterRenderer.kt:175)
    at com.google.maps.android.compose.clustering.ComposeUiClusterRenderer.onBeforeClusterItemRendered(ClusterRenderer.kt:167)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$CreateMarkerTask.perform(DefaultClusterRenderer.java:1060)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$CreateMarkerTask.access$1900(DefaultClusterRenderer.java:1027)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.performNextTask(DefaultClusterRenderer.java:740)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.handleMessage(DefaultClusterRenderer.java:710)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)