From b022d4878deba41b3be79e802120683950930896 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Wed, 2 Apr 2025 21:12:20 +0200 Subject: [PATCH] Fix rare crash LatLngAnimator (#3352) --- .../android/location/LocationAnimatorCoordinator.java | 7 ++++++- .../android/location/LocationAnimatorCoordinatorTest.kt | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationAnimatorCoordinator.java b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationAnimatorCoordinator.java index c48a15b51..8392a2e7d 100644 --- a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationAnimatorCoordinator.java +++ b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationAnimatorCoordinator.java @@ -334,7 +334,8 @@ final class LocationAnimatorCoordinator { createNewCameraAdapterAnimator(ANIMATOR_TILT, new Float[] {previousTiltLevel, targetTilt}, cancelableCallback); } - private void createNewLatLngAnimator(@MapLibreAnimator.Type int animatorType, LatLng previous, LatLng target) { + private void createNewLatLngAnimator(@MapLibreAnimator.Type int animatorType, + @NonNull LatLng previous, @NonNull LatLng target) { createNewLatLngAnimator(animatorType, new LatLng[] {previous, target}); } @@ -430,6 +431,10 @@ final class LocationAnimatorCoordinator { LatLng currentTarget = animator.getTarget(); LatLng previousCameraTarget = currentCameraPosition.target; + if (previousCameraTarget == null) { + return false; + } + createNewLatLngAnimator(ANIMATOR_CAMERA_LATLNG, previousCameraTarget, currentTarget); return immediateAnimation(projection, previousCameraTarget, currentTarget); diff --git a/platform/android/MapLibreAndroid/src/test/java/org/maplibre/android/location/LocationAnimatorCoordinatorTest.kt b/platform/android/MapLibreAndroid/src/test/java/org/maplibre/android/location/LocationAnimatorCoordinatorTest.kt index 37e40ad67..5a0cce63f 100644 --- a/platform/android/MapLibreAndroid/src/test/java/org/maplibre/android/location/LocationAnimatorCoordinatorTest.kt +++ b/platform/android/MapLibreAndroid/src/test/java/org/maplibre/android/location/LocationAnimatorCoordinatorTest.kt @@ -583,6 +583,15 @@ class LocationAnimatorCoordinatorTest { assertFalse(locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_LATLNG].isStarted) } + // regression test for crash https://github.com/maplibre/maplibre-native/issues/3294 + @Test + fun resetAllCameraAnimations_null_target() { + locationAnimatorCoordinator.feedNewLocation(Location(""), CameraPosition.DEFAULT, true) + + val cameraPosition = CameraPosition.Builder().build() + locationAnimatorCoordinator.resetAllCameraAnimations(cameraPosition, false) + } + @Test fun cancelZoomAnimators() { locationAnimatorCoordinator.feedNewZoomLevel(