Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash MapEffect snapshot: Can't take a snapshot while executing in the background #590

Open
el-qq opened this issue Jul 1, 2024 · 1 comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@el-qq
Copy link
Contributor

el-qq commented Jul 1, 2024

Environment details

Library version and other environment information: 5.0.4

Steps to reproduce

  1. insert the code from the example
  2. swipe down and/or swipe up and down quickly in one place
  3. Crash happens

Code example


@OptIn(MapsComposeExperimentalApi::class)
@Composable
fun SnapshotBackground() {
    LazyColumn(
        modifier = Modifier.fillMaxSize(),
        contentPadding = PaddingValues(
            horizontal = 12.dp,
            vertical = 12.dp,
        )
    ) {
        items(250) {
            val mapBitmap = remember { mutableStateOf<Bitmap?>(null) }
            Box(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(300.dp)
                    .padding(bottom = 12.dp),
                contentAlignment = Alignment.Center,
            ) {
                if (mapBitmap.value == null) {
                    val isMapLoaded = remember { mutableStateOf(false) }
                    val cameraPositionState =
                        rememberCameraPositionState { position = CameraPosition.fromLatLngZoom(singapore, 16f) }

                    GoogleMap(
                        cameraPositionState = cameraPositionState,
                        uiSettings = MapUiSettings(
                            compassEnabled = false,
                            indoorLevelPickerEnabled = false,
                            mapToolbarEnabled = false,
                            myLocationButtonEnabled = false,
                            rotationGesturesEnabled = false,
                            scrollGesturesEnabled = false,
                            scrollGesturesEnabledDuringRotateOrZoom = false,
                            tiltGesturesEnabled = false,
                            zoomControlsEnabled = false,
                            zoomGesturesEnabled = false
                        ),
                        onMapLoaded = {
                            isMapLoaded.value = true
                        },
                    ) {
                        if (isMapLoaded.value) {
                            MapEffect { map ->
                                map.snapshot { snapshot ->
                                    mapBitmap.value = snapshot
                                }
                            }
                        }

                    }

                    Icon(
                        modifier = Modifier
                            .fillMaxSize()
                            .background(MaterialTheme.colors.surface),
                        painter = painterResource(id = android.R.drawable.star_on),
                        contentDescription = "Analytics section"
                    )

                } else {
                    Image(
                        bitmap = mapBitmap.value!!.asImageBitmap(),
                        contentDescription = null
                    )
                }
            }
        }
    }
}

Stack trace

 FATAL EXCEPTION: main
Process: com.google.maps.android.compose, PID: 9046
java.lang.IllegalStateException: Can't take a snapshot while executing in the background.
  at com.google.maps.api.android.lib6.impl.a.a(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:20)
    at com.google.maps.api.android.lib6.phoenix.dl.run(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:9)
     at android.os.Handler.handleCallback(Handler.java:959)
     at android.os.Handler.dispatchMessage(Handler.java:100)
      at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8501
@el-qq el-qq added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jul 1, 2024
@kikoso
Copy link
Collaborator

kikoso commented Jul 26, 2024

Hi @el-qq ,

This is a intended behavior on the subjacent Maps SDK when the map is not visible, see issue reported here.

Can you verify that your map is not visible on the screen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
2 participants