android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

MarkerComposable throw `Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0`

Open Abdelsattar opened this issue 1 year ago • 3 comments

Hello, I'm working with Google Maps Compose and now I get some Firebase crashes related to markerComposable withe 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)
       ```


this is my following code : 

@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)
            )
        }

    }
  }
 }

Environment details

  1. API Google Maps compose
  2. it's happening at multiple Version From Android 9 ->14
  3. Google Maps compose version v2.14.0

Steps to reproduce

  1. I can't reproduce my local but the crashes caught by Firebase affect around 1% of the users

Thanks!

Abdelsattar avatar Jan 29 '24 10:01 Abdelsattar

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@Abdelsattar Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

wangela avatar Jan 29 '24 10:01 wangela

I have the same issue. This is the full stack trace from sentry in my case:

android.graphics.Bitmap in createBitmap in Zeile 1170
android.graphics.Bitmap in createBitmap in Zeile 1118
android.graphics.Bitmap in createBitmap in Zeile 1077
com.example.common.compose.maps.RememberComposeBitmapDescriptorKt in renderComposableToBitmapDescriptor in Zeile 58
com.example.common.compose.maps.RememberComposeBitmapDescriptorKt in access$renderComposableToBitmapDescriptor in Zeile 1
com.example.common.compose.maps.RememberComposeBitmapDescriptorKt in rememberComposeBitmapDescriptor in Zeile 29
com.example.common.compose.maps.MarkerKt in MarkerComposable-pMp3byo in Zeile 248
com.example.DetailScreenKt$MapCard$1$1$3 in invoke in Zeile 638
com.example.DetailScreenKt$MapCard$1$1$3 in invoke in Zeile 637
androidx.compose.runtime.internal.ComposableLambdaImpl in invoke in Zeile 109
androidx.compose.runtime.internal.ComposableLambdaImpl in invoke in Zeile 35
com.example.common.compose.maps.GoogleMapKt$GoogleMap$4$1$1$1 in invoke in Zeile 142
com.example.common.compose.maps.GoogleMapKt$GoogleMap$4$1$1$1 in invoke in Zeile 141
androidx.compose.runtime.internal.ComposableLambdaImpl in invoke in Zeile 109
androidx.compose.runtime.internal.ComposableLambdaImpl in invoke in Zeile 35
androidx.compose.runtime.CompositionLocalKt in CompositionLocalProvider in Zeile 248
com.example.common.compose.maps.GoogleMapKt$GoogleMap$4$1$1 in invoke in Zeile 139
com.example.common.compose.maps.GoogleMapKt$GoogleMap$4$1$1 in invoke in Zeile 128
androidx.compose.runtime.internal.ComposableLambdaImpl in invoke in Zeile 109
androidx.compose.runtime.internal.ComposableLambdaImpl in invoke in Zeile 35
androidx.compose.runtime.ActualJvm_jvmKt in invokeComposable in Zeile 90
androidx.compose.runtime.ComposerImpl in doCompose in Zeile 3302
androidx.compose.runtime.ComposerImpl in composeContent$runtime_release in Zeile 3235
androidx.compose.runtime.CompositionImpl in composeContent in Zeile 723
androidx.compose.runtime.Recomposer in composeInitial$runtime_release in Zeile 1071
androidx.compose.runtime.ComposerImpl$CompositionContextImpl in composeInitial$runtime_release in Zeile 3599
androidx.compose.runtime.CompositionImpl in composeInitial in Zeile 631
androidx.compose.runtime.CompositionImpl in setContent in Zeile 617
com.example.common.compose.maps.GoogleMapKt$GoogleMap$4 in invokeSuspend in Zeile 284
kotlin.coroutines.jvm.internal.BaseContinuationImpl in resumeWith in Zeile 33
kotlinx.coroutines.DispatchedTask in run in Zeile 108
androidx.compose.ui.platform.AndroidUiDispatcher in performTrampolineDispatch in Zeile 81
androidx.compose.ui.platform.AndroidUiDispatcher in access$performTrampolineDispatch in Zeile 41
androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1 in run in Zeile 57
android.os.Handler in handleCallback in Zeile 959
android.os.Handler in dispatchMessage in Zeile 100
android.os.Looper in loopOnce in Zeile 232
android.os.Looper in loop in Zeile 317
android.app.ActivityThread in main in Zeile 8501
java.lang.reflect.Method in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run in Zeile 552
com.android.internal.os.ZygoteInit in main in Zeile 878

My code looks similar to the example above. I could also reproduce it locally, but only once. All I did was navigate back and forth (fragment based navigation) between my main screen and the screen which contains the map very fast for many times. So it is probably some kind of race condition.

ln-12 avatar Mar 15 '24 08:03 ln-12

This crash can be forced using this project: https://github.com/ln-12/GoogleMapsCrashReproducer

ln-12 avatar Mar 18 '24 08:03 ln-12

:tada: This issue has been resolved in version 5.0.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

googlemaps-bot avatar Jun 24 '24 15:06 googlemaps-bot

:tada: This issue has been resolved in version 6.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

googlemaps-bot avatar Jul 03 '24 15:07 googlemaps-bot

Maybe this need to be reopened since we encountered this using 6.4.0.

mariohide avatar Dec 29 '24 03:12 mariohide

Same for us, I already provided some more information in https://github.com/googlemaps/android-maps-compose/issues/641#issuecomment-2554105613

ln-12 avatar Dec 29 '24 09:12 ln-12

I faced the same issue when I reload the fragment that conatin Maps and faceing the same error:

tried this with versions: 6.1.1 , 6.4.4

   java.lang.IllegalStateException: The ComposeView was measured to have a width or height of zero. Make sure that the content has a non-zero size.

and I updated with the following code

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

  locations.onEachIndexed { index, latLng ->

    MarkerComposable(
        state = MarkerState(latLng),
    ) {
        val markerSequence = getMarkerSequence(index)
        Box(             
               modifier = Modifier.size(40.dp, 62.dp),
               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)
            )
        }

    }
  }
 }

I don't know why it throw this error, because I'm passing the icon drawer which always have a size and there is no size paramter inside MarkerComposable

Abdelsattar avatar Feb 10 '25 15:02 Abdelsattar

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Having the exact same problem on 6.5.0. This has not been solved. It tells me "The ComposeView was measured to have a width or height of zero" even tought I have forced a size and everything is just as Google recommends.

CarloskHard avatar Mar 17 '25 18:03 CarloskHard

I faced the same issue when I reload the fragment that conatin Maps and faceing the same error:

tried this with versions: 6.1.1 , 6.4.4

   java.lang.IllegalStateException: The ComposeView was measured to have a width or height of zero. Make sure that the content has a non-zero size.

and I updated with the following code

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

  locations.onEachIndexed { index, latLng ->

    MarkerComposable(
        state = MarkerState(latLng),
    ) {
        val markerSequence = getMarkerSequence(index)
        Box(             
               modifier = Modifier.size(40.dp, 62.dp),
               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)
            )
        }

    }
  }
 }

I don't know why it throw this error, because I'm passing the icon drawer which always have a size and there is no size paramter inside MarkerComposable

Tried on 6.5.2 that is released 2025/03/22, still same issue, even for a simple Text like

MarkerComposable(
      state = markerState,
    ) {
      Text(
        text = "Hello",
        color = Color.White,
        modifier = Modifier
          .padding(top = 4.dp)
          .size(40.dp)
      )
    }

aryoxp avatar Mar 22 '25 22:03 aryoxp

Did anyone try 6.5.3 with this commit https://github.com/googlemaps/android-maps-compose/pull/701?

martintoften avatar May 01 '25 07:05 martintoften

@martintoften I tried with 6.6.0 and i m still getting the same issue.

way2jatin avatar May 02 '25 20:05 way2jatin

Same, still getting the same issue!

OcheretnyArtem avatar May 28 '25 15:05 OcheretnyArtem

we still getting the same issue

abualgait avatar Jul 03 '25 08:07 abualgait

Hi @dkhawk, This issue is causing a significant number of crashes—over 7,000 occurrences—which is impacting our crash-free sessions rate. Let’s reopen it and prioritize fixing it as soon as possible please.

abualgait avatar Jul 21 '25 07:07 abualgait

Hi folks.

I can't reproduce this using the LocationMarker composable proposed here, or the snippet proposed here.

Would you have a full sample that can be downloaded to test it out?

kikoso avatar Jul 21 '25 10:07 kikoso

Hi folks,

One update: this happens within a Fragment, not within an Activity. Probably due to the fact that when a ComposeView is created in onCreateView and immediately populated, its layout pass might not have completed when MarkerComposable attempts to snapshot its content.

kikoso avatar Jul 21 '25 13:07 kikoso

Hi folks.

I can't reproduce this using the LocationMarker composable proposed here, or the snippet proposed here.

Would you have a full sample that can be downloaded to test it out?

Hi @kikoso , maybe this will be helpful:

https://github.com/googlemaps/android-maps-compose/issues/641#issuecomment-2568840901

mariohide avatar Jul 21 '25 14:07 mariohide

This crash can be forced using this project: https://github.com/ln-12/GoogleMapsCrashReproducer

@ln-12 , would you be able to take a look at this PR in your sample repository and see if it fixes the issue?

kikoso avatar Jul 21 '25 15:07 kikoso

@kikoso As stated in the PR, the 0dp size was there to force the crash.

We currently still go with my workaround proposed here as there seems to be no real solution so far. After my PR, I cannot reproduce it locally anymore but our logging shows that it still (rarely) happens on user devices.

ln-12 avatar Jul 21 '25 15:07 ln-12