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.15k stars 135 forks source link

Camera stopped during a cancellation #52

Open mcfboss opened 2 years ago

mcfboss commented 2 years ago

Hello,

I have a map in a Box where it has some BottomSheet like composables on top that appear from the bottom when you click on some of the markers, kind of google maps style. The problem comes when I flick the map and before the camera stops moving I click anywhere in the map to stop moving it, then I get this exception :

com.google.maps.api.android.lib6.common.apiexception.c: Camera stopped during a cancellation

I thought it was related to having composables on top, but the problem is still there if I remove them. The problem is only occuring with fast camera movements and suddenly stopping them clicking the map or some marker.

Any ideas what could it be? Thank you!

jpoehnelt commented 2 years ago

@mcfboss Please take a moment to fill out this short survey. Thank you!

This is an automated message, feel free to ignore.

jpoehnelt commented 2 years ago

@mcfboss Thank you for opening this issue. 🙏 Please check out these other resources that might be applicable:

This is an automated message, feel free to ignore.

arriolac commented 2 years ago

I'm not able to repro this in the sample app. Can you share a snippet of your implementation?

v170nix commented 2 years ago

Hello Unfortunately, I can't share a minimal example, but I can add data.

========

2022-07-26 19:22:44.576 28741-28741/org.sunexplorer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.sunexplorer, PID: 28741
    com.google.maps.api.android.lib6.common.apiexception.c: Camera stopped during a cancellation
        at com.google.maps.api.android.lib6.common.m.i(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):0)
        at com.google.maps.api.android.lib6.gmm6.api.c.t(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):1)
        at com.google.maps.api.android.lib6.impl.bj.P(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):1)
        at com.google.android.gms.maps.internal.i.ba(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):202)
        at en.onTransact(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):4)
        at android.os.Binder.transact(Binder.java:1100)
        at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps@@18.1.0:2)
        at com.google.android.gms.maps.internal.zzg.stopAnimation(com.google.android.gms:play-services-maps@@18.1.0:2)
        at com.google.android.gms.maps.GoogleMap.stopAnimation(com.google.android.gms:play-services-maps@@18.1.0:1)
        at com.google.maps.android.compose.CameraPositionState.animate(CameraPositionState.kt:221)
        at com.google.maps.android.compose.CameraPositionState$animate$1.invokeSuspend(Unknown Source:15)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
        at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:190)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:328)
        at com.google.maps.android.compose.CameraPositionState$performAnimateCameraLocked$1.onCancel(CameraPositionState.kt:234)
        at com.google.android.gms.maps.zzaa.zzb(com.google.android.gms:play-services-maps@@18.1.0:1)
        at com.google.android.gms.maps.internal.zzc.zza(com.google.android.gms:play-services-maps@@18.1.0:1)
        at com.google.android.gms.internal.maps.zzb.onTransact(com.google.android.gms:play-services-maps@@18.1.0:3)
        at android.os.Binder.transact(Binder.java:1100)
        at em.bc(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):2)
        at com.google.maps.api.android.lib6.gmm6.api.c.o(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):9)
        at com.google.maps.api.android.lib6.gmm6.vector.cm.B(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):1)
        at com.google.maps.api.android.lib6.gmm6.vector.cm.h(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):9)
        at com.google.maps.api.android.lib6.gmm6.api.ak.f(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):2)
        at com.google.maps.api.android.lib6.gmm6.api.ak.e(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):0)
        at com.google.maps.api.android.lib6.gmm6.api.f.j(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):5)
        at com.google.maps.api.android.lib6.gmm6.vector.l.a(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):17)
        at com.google.maps.api.android.lib6.gmm6.vector.ae.U(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):15)
        at com.google.maps.api.android.lib6.gmm6.vector.cp.onSingleTapConfirmed(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):0)
        at com.google.maps.api.android.lib6.impl.gesture.b.onSingleTapConfirmed(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):0)
2022-07-26 19:22:44.577 28741-28741/org.sunexplorer E/AndroidRuntime:     at com.google.maps.api.android.lib6.impl.gesture.c.handleMessage(:com.google.android.gms.dynamite_mapsdynamite@222615097@22.26.15 (190400-0):2)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8663)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
        Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@865e2e1, androidx.compose.runtime.BroadcastFrameClock@9885806, StandaloneCoroutine{Cancelling}@4837ec7, AndroidUiDispatcher@187ccf4]

Samsung A71 Android 11 play-services-maps:18.1.0 maps-compose:1.0.0

==========

kyle-gonzales commented 1 year ago

Hello! I think this error is caused by a CancellationException that did not reach the parent scope probably because it was caught in a try-catch block. This is an error that revolves around exception handling with coroutines.

Stopping the animation cancels the coroutine and throws a CancellationException. This cancellation exception should be rethrown.

try {
  scope.animate(CameraUpdateFactory.zoomIn())
} catch (e: Exception){
  if (e is CancellationException) throw e
  // catch other errors here
}

Hope this helps!

AlbertoDroid commented 7 months ago

Hi @arriolac I'm running into the same issue, for me happens when I have minify enabled and when trying to use cameraPositionState.animate. The map target won't move and when I try to move it manually the exception is thrown.

If I disable minify the crash doesn't happen. Are there proguard rules we need to use?