MarkerComposable throw `Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0`
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
- API Google Maps compose
- it's happening at multiple Version From Android 9 ->14
- Google Maps compose version v2.14.0
Steps to reproduce
- I can't reproduce my local but the crashes caught by Firebase affect around 1% of the users
Thanks!
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:
- Check the issue tracker - bugs and feature requests for Google Maps Platform APIs and SDKs
- Open a support case - Get 1:1 support in Cloud Console.
- Discord - chat with other developers
- StackOverflow - use the
google-mapstag
This is an automated message, feel free to ignore.
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.
This crash can be forced using this project: https://github.com/ln-12/GoogleMapsCrashReproducer
:tada: This issue has been resolved in version 5.0.4 :tada:
The release is available on:
v5.0.4- GitHub release
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 6.0.0 :tada:
The release is available on:
v6.0.0- GitHub release
Your semantic-release bot :package::rocket:
Maybe this need to be reopened since we encountered this using 6.4.0.
Same for us, I already provided some more information in https://github.com/googlemaps/android-maps-compose/issues/641#issuecomment-2554105613
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
🎉 This issue has been resolved in version 6.0.0 🎉
The release is available on:
v6.0.0- GitHub release
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.
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)
)
}
Did anyone try 6.5.3 with this commit https://github.com/googlemaps/android-maps-compose/pull/701?
@martintoften I tried with 6.6.0 and i m still getting the same issue.
Same, still getting the same issue!
we still getting the same issue
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.
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 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.
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
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?