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
476 stars 133 forks source link

Calling easeTo with empty CameraOptions crashes #2454

Closed jliumo closed 2 months ago

jliumo commented 3 months ago

Environment

Observed behavior and steps to reproduce

Calling com.mapbox.maps.plugin.animation.easeTo with empty CameraOptions crashes the application, because it tries to spread an empty array.

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
   at android.animation.AnimatorSet.playTogether(AnimatorSet.java:233)
   at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl.startHighLevelAnimation(CameraAnimationsPluginImpl.kt:1005)
   at com.mapbox.maps.plugin.animation.CameraAnimationsPluginImpl.easeTo(CameraAnimationsPluginImpl.kt:723)
   at com.mapbox.maps.plugin.animation.CameraAnimationsUtils$easeTo$1.invoke(CameraAnimationsExt.kt:40)
   at com.mapbox.maps.plugin.animation.CameraAnimationsUtils$easeTo$1.invoke(CameraAnimationsExt.kt:40)
   at com.mapbox.maps.MapboxMap.cameraAnimationsPlugin(MapboxMap.kt:2245)
   at com.mapbox.maps.plugin.animation.CameraAnimationsUtils.easeTo(CameraAnimationsExt.kt:40)
   at com.mapbox.maps.plugin.animation.CameraAnimationsUtils.easeTo$default(CameraAnimationsExt.kt:36)

Expected behavior

The call shouldn't do anything.

Notes / preliminary analysis

This causes problems for us, because even asynchronous cameraForCoordinates called during layout changes sometimes returns empty cameraState causing whole application to crash, while it can be checked by com.mapbox.maps.util.isEmpty I think it would be more developer friendly if it didn't cause crash

W  [maps-core]: {}[General]: Unable to calculate camera for given bounds/geometry, padding is greater than map's width or height.
E  [maps-android\Mbgl-MapboxMap]: Error occurred in asynchronous cameraForCoordinates: Unable to calculate cameraForCoordinates, either padding exceeds screensize or screensize is not set, empty cameraState will be returned
flasher297 commented 3 months ago

Thank you for the detailed description of the issue. We've raised an internal ticket to fix it and will come back as soon as it is ready.

flasher297 commented 2 months ago

@jliumo @naftalibeder we introduced a fix for this bug in v11.7.0-rc.1 release of SDK.

Fix a crash when calling CameraAnimationsPlugin.easeTo() with empty camera options or CameraAnimationsPlugin.playAnimatorsSequentially() / CameraAnimationsPlugin.playAnimatorsTogether() with an empty array of animators. Fix ongoing animations being canceled when CameraAnimationsPlugin.flyTo() with empty camera options is called.

Test it and rise a ticket if you still have an issue.