mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
465 stars 131 forks source link

MapPluginExtensionsDelegate#flyTo crashes with cameraForCoordinates and frequent padding updates #1143

Closed munnitz closed 2 years ago

munnitz commented 2 years ago

Environment

Observed behavior and steps to reproduce

Crash when calling map.flyTo(map.cameraForCoordinates(visibleCoordinates, padding = padding))

We place a bottomsheet above our map and update the padding every time the bottomsheet is dragged in order to correctly center the visibleCoordinates. Problem ist that sometimes the app crashes when dragging the bottomsheet and by that updating the padding values. Resulting in the following stack trace:

Process: xx.xxxx.xxx.xxx, PID: 31079
    java.lang.Error: latitude must not be NaN
        at com.mapbox.maps.Projection.unproject(Native Method)
        at com.mapbox.maps.MapboxMap.unproject(MapboxMap.kt:688)
        at com.mapbox.maps.plugin.animation.CameraAnimatorsFactory$getFlyTo$animators$1.evaluate(CameraAnimatorsFactory.kt:367)
        at com.mapbox.maps.plugin.animation.CameraAnimatorsFactory$getFlyTo$animators$1.evaluate(CameraAnimatorsFactory.kt:27)
        at android.animation.KeyframeSet.getValue(KeyframeSet.java:202)
        at android.animation.PropertyValuesHolder.calculateValue(PropertyValuesHolder.java:1017)
        at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1553)
        at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:684)
        at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:647)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1079)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1098)
        at com.mapbox.maps.plugin.animation.animator.CameraAnimator.start(CameraAnimator.kt:82)
        at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1091)
        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(CameraAnimationsPluginImpl.kt:858)
        at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl.flyTo(CameraAnimationsPluginImpl.kt:701)
        at com.mapbox.maps.plugin.animation.CameraAnimationsUtils$flyTo$1.invoke(CameraAnimationsExt.kt:58)
        at com.mapbox.maps.plugin.animation.CameraAnimationsUtils$flyTo$1.invoke(Unknown Source:2)
        at com.mapbox.maps.MapboxMap.cameraAnimationsPlugin(MapboxMap.kt:1403)
        at com.mapbox.maps.plugin.animation.CameraAnimationsUtils.flyTo(CameraAnimationsExt.kt:58)
        at com.mapbox.maps.plugin.animation.CameraAnimationsUtils.flyTo$default(CameraAnimationsExt.kt:57)
        at xx.xxxx.xxx.xxx.fragment.map.MapboxMapKt.handleCameraPosition(MapboxMap.kt:435)
        at xx.xxxx.xxx.xxx.fragment.map.MapboxMapKt.access$handleCameraPosition(MapboxMap.kt:1)
        at xx.xxxx.xxx.xxx.fragment.map.MapboxMapKt$MapboxMap$3$4.invokeSuspend(MapboxMap.kt:183)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
        at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
        at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

However I am not passing any coordinates with Lat=NaN. At the time of the crash, visibleCoordinates contains the following data

Point{type=Point, bbox=null, coordinates=[9.969853, 53.54533]}, 
Point{type=Point, bbox=null, coordinates=[9.969883, 53.54533]}, 
Point{type=Point, bbox=null, coordinates=[9.969865, 53.545222]}, 
Point{type=Point, bbox=null, coordinates=[9.969865, 53.545213]}, 
Point{type=Point, bbox=null, coordinates=[9.969864, 53.545186]}, 
Point{type=Point, bbox=null, coordinates=[9.969864, 53.545186]}, 
Point{type=Point, bbox=null, coordinates=[9.969864, 53.54515]}, 
Point{type=Point, bbox=null, coordinates=[9.969864, 53.54515]}, 
Point{type=Point, bbox=null, coordinates=[9.969847, 53.545096]}, 
Point{type=Point, bbox=null, coordinates=[9.970058, 53.545086]}, 
Point{type=Point, bbox=null, coordinates=[9.970058, 53.545086]}, 
Point{type=Point, bbox=null, coordinates=[9.970059, 53.545121]}, 
Point{type=Point, bbox=null, coordinates=[9.970059, 53.545121]}

The padding is [top: 168.0, left: 105.0, bottom: 1002.0, right: 105.0]

Calling map.flyTo(map.cameraForCoordinates(visibleCoordinates)) without the padding seems to work fine.

Chaoba commented 2 years ago

@munnitz Thanks for reporting. What's the width and height of mapview?

munnitz commented 2 years ago

@Chaoba The map's dimensions are w1080 x h1794

Chaoba commented 2 years ago

@munnitz I have tried with your points and padding, but still can't reproduce this issue. Can you provider a demo or a branch in this repo that could reproduce this? Thanks.

adi9090 commented 2 years ago

We got the same issue as reported by @munnitz
On map we are showing location of an object X and user location, with priority on location of an X. If we zoom in to user location shown on map and call the flyTo(cameraPosition, animationOptions) with valid user coordinates, we got the same crash.

kiryldz commented 2 years ago

Will be fixed by https://github.com/mapbox/mapbox-maps-android/pull/1271 and available in v10.5.0-rc.1 release.