Skip to content

Crash with flyTo with camera position set with cameraForCoordinateBounds #2289

@boiler23

Description

@boiler23

Environment

  • Android OS version: 12, 14
  • Devices affected: Lenovo Tab P11 Plus, Samsung Galaxy S23 Ultra, Samsung S21 FE 5G
  • Maps SDK Version: 11.0.0, 11.1.0, 11.2.0-rc.1

Observed behavior and steps to reproduce

Sometimes, in my app, I want to focus the map on a specific region, so I'm setting the map via the flyTo method to the camera options, defined by a cameraForCoordinateBounds method. The code looks roughly like this:

val update = mbMap.cameraForCoordinateBounds(
      coordinateBounds,
      bearing = 0.0,
      pitch = 0.0,
      boundsPadding = EdgeInsets(...),
)
mbMap.flyTo(cameraOptions, mapAnimationOptions { })

Sometimes, this leads to the following crash:

Fatal Exception: java.lang.Error: latitude must not be NaN
       at com.mapbox.maps.Projection.unproject(Projection.java)
       at com.mapbox.maps.MapboxMap.unproject(MapboxMap.kt:1148)
       at com.mapbox.maps.plugin.animation.CameraAnimatorsFactory.getFlyTo$lambda$41(CameraAnimatorsFactory.kt:421)
       at android.animation.KeyframeSet.getValue(KeyframeSet.java:202)
       at android.animation.PropertyValuesHolder.calculateValue(PropertyValuesHolder.java:1017)
       at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1561)
       at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:692)
       at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:655)
       at android.animation.ValueAnimator.start(ValueAnimator.java:1087)
       at android.animation.ValueAnimator.start(ValueAnimator.java:1106)
       at com.mapbox.maps.plugin.animation.animator.CameraAnimator.access$cancel$s-741060776(CameraAnimator.kt:17)
       at com.mapbox.maps.plugin.animation.animator.CameraAnimator.access$start$s-741060776(CameraAnimator.kt:17)
       at com.mapbox.maps.plugin.animation.animator.CameraAnimator$start$1.invoke(CameraAnimator.kt:95)
       at com.mapbox.maps.plugin.animation.animator.CameraAnimator$start$1.invoke(CameraAnimator.kt:88)
       at com.mapbox.maps.threading.AnimationThreadController.postOnMainThread(AnimationThreadController.kt:67)
       at com.mapbox.maps.threading.AnimationThreadController.postOnAnimatorThread(AnimationThreadController.kt:90)
       at com.mapbox.maps.plugin.animation.animator.CameraAnimator.start(CameraAnimator.kt:88)
       at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1099)
       at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1149)
       at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1234)
       at android.animation.AnimatorSet.start(AnimatorSet.java:729)
       at android.animation.AnimatorSet.start(AnimatorSet.java:684)
       at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl$startHighLevelAnimation$2$1.invoke(CameraAnimationsPluginImpl.kt:976)
       at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl$startHighLevelAnimation$2$1.invoke(CameraAnimationsPluginImpl.kt:976)
       at com.mapbox.maps.threading.AnimationThreadController.postOnMainThread(AnimationThreadController.kt:67)
       at com.mapbox.maps.threading.AnimationThreadController.postOnAnimatorThread(AnimationThreadController.kt:90)
       at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl.startHighLevelAnimation(CameraAnimationsPluginImpl.kt:976)
       at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl.flyTo(CameraAnimationsPluginImpl.kt:805)
       at com.mapbox.maps.plugin.animation.CameraAnimationsUtils$flyTo$1.invoke(CameraAnimationsExt.kt:59)
       at com.mapbox.maps.plugin.animation.CameraAnimationsUtils$flyTo$1.invoke(CameraAnimationsExt.kt:59)
       at com.mapbox.maps.MapboxMap.cameraAnimationsPlugin(MapboxMap.kt:2082)
       at com.mapbox.maps.plugin.animation.CameraAnimationsUtils.flyTo(CameraAnimationsExt.kt:59)
       at com.mapbox.maps.plugin.animation.CameraAnimationsUtils.flyTo$default(CameraAnimationsExt.kt:55)

I don't have specific steps to reproduce, but I observe those crashes in Firebase, specifically on the Lenovo device mentioned above. I noticed this once on my device as well. However, the crash dissolved on my device after some time without changing the coordinate bounds. It may depend on the initial camera position. The coordinate bounds, in that case, were 100% valid.
My initial assumption was that the coordinate region was invalid, so I added a few checks: coordinateBounds.isValid && coordinateBounds.isBounded && !coordinateBounds.isEmpty. Unfortunately, that didn't help; the crash is still there.
Note: With Mapbox 10, everything worked well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions