Fix rare crash LatLngAnimator (#3352)

This commit is contained in:
Bart Louwers
2025-04-02 21:12:20 +02:00
committed by GitHub
parent 5a368624ec
commit b022d4878d
2 changed files with 15 additions and 1 deletions

View File

@@ -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);

View File

@@ -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(