Sattar
Sattar

Reputation: 2632

Google Maps Compose : MarkerComposable Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0

I'm working with Google Maps Compose and now I get some Firebase crashes related to markerComposable

I know that this exception happened because of createBitmap but I don't have access to it even to fix it as I'm using markerComposable and I think this is happening inside that.

How I can fix that as most of the answers found is to make sure that the executing code should happen after Google Maps is already initialized and this is already done in my case.

PS: I can't reproduce the problem I caught it through Firebase it affects around 1% of my app users with different Android versions.

the following exception:

Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0
       at android.graphics.Bitmap.createBitmap(Bitmap.java:1148)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:1115)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:1065)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:1026)
       at com.google.maps.android.compose.RememberComposeBitmapDescriptorKt.renderComposableToBitmapDescriptor(RememberComposeBitmapDescriptor.kt:58)
       at com.google.maps.android.compose.RememberComposeBitmapDescriptorKt.access$renderComposableToBitmapDescriptor(RememberComposeBitmapDescriptor.kt:1)
       at com.google.maps.android.compose.RememberComposeBitmapDescriptorKt.rememberComposeBitmapDescriptor(RememberComposeBitmapDescriptor.kt:29)
       at com.google.maps.android.compose.MarkerKt.MarkerComposable-pMp3byo(Marker.kt:239)
       ```

@Composable
fun MapScreen(
 ...
) {

 GoogleMap(
       modifier = Modifier
          .fillMaxWidth()
          .padding(bottom = sheetPeekHeight - 8.dp),
      cameraPositionState = cameraPositionState,
      properties = if (locationPermissionState.status.isGranted) MapProperties(isMyLocationEnabled = true) else MapProperties(
          isMyLocationEnabled = false
     ),
      uiSettings = MapUiSettings(zoomControlsEnabled = false)
   ) {
      LocationMarkers(locations, getMarkerSequence)
 } 
}

@Composable
fun LocationMarkers(
   locations: List<LatLng>,
   getMarkerSequence: (Int) -> String
 ) {

  locations.onEachIndexed { index, latLng ->

    MarkerComposable(
        state = MarkerState(latLng),
    ) {
        val markerSequence = getMarkerSequence(index)
        Box(contentAlignment = Alignment.Center) {
            Image(
                painter = painterResource(id = R.drawable.ic_my_icon),
                contentDescription = ""
            )

            Text(
                text = markerSequence,
                color = Color.White,
                modifier = Modifier
                    .padding(top = 4.dp)
                    .align(Alignment.TopCenter)
            )
        }

    }
  }
 }

Upvotes: 2

Views: 320

Answers (0)

Related Questions