Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

NullPointer/Force Closure when animating LocationComponent and zooming at same time #14246

Closed
carstenhag opened this issue Mar 27, 2019 · 4 comments
Labels
Android Mapbox Maps SDK for Android

Comments

@carstenhag
Copy link

carstenhag commented Mar 27, 2019

Excerpt of the code the bug occurs with:

val locationComponent = mapboxMap.locationComponent
mapboxMap.style?.let {
    locationComponent.activateLocationComponent(
            this@MainActivity,
            it,
            LocationComponentOptions.builder(this).build()
    )
}

locationComponent.isLocationComponentEnabled = true
locationComponent.renderMode = RenderMode.COMPASS

val animatedOptions = LocationComponentOptions.builder(this@MainActivity)
val animator = ValueAnimator.ofFloat(1f, 1.3f).apply {
    addUpdateListener {
        locationComponent.applyStyle(animatedOptions.minZoomIconScale(it.animatedValue as Float).build())
    }
    interpolator = AccelerateDecelerateInterpolator()
    duration = 1000
    repeatMode = ValueAnimator.REVERSE
    repeatCount = ValueAnimator.INFINITE
}

animator.start()

Steps to reproduce

Video: https://drive.google.com/file/d/1Gc83IPWKpXzhkKOx27--r4dBSGmSVHlA/view?usp=sharing

  1. Animate a LocationComponent by applying styles inside a ValueAnimator
  2. Start the app
  3. Zoom the map rapidly in and out, sometimes zooming mildly. Does not happen always, so rather irregular. After trying for 20 seconds it crashes almost every time for me though.

Expected behavior

App does not crash, animating the component and zooming the map should not cause NullPointers/Crashes

Actual behavior

NullPointerException inside this code (from the SDK) and the app crashes:

NativeMapView.java:325

  @Override
  public void setZoom(double zoom, @NonNull PointF focalPoint, long duration) {
    if (checkState("setZoom")) {
      return;
    }
    nativeSetZoom(zoom, focalPoint.x / pixelRatio, focalPoint.y / pixelRatio, duration);
  }
2019-03-27 10:35:24.063 611-611/? W/auditd: type=1400 "thermal-engine""u:object_r:system_prop:s0""tmpfs"
2019-03-27 10:35:28.117 14670-14670/de.chagemann.stadtplanmosbach.debug E/ViewRootImpl: mView does not exist, so discard the remaining points. java.lang.NullPointerException: Attempt to read from field 'float android.graphics.PointF.x' on a null object reference
2019-03-27 10:35:28.125 14670-14670/de.chagemann.stadtplanmosbach.debug E/AndroidRuntime: FATAL EXCEPTION: main
    Process: de.chagemann.stadtplanmosbach.debug, PID: 14670
    java.lang.NullPointerException: Attempt to read from field 'float android.graphics.PointF.x' on a null object reference
        at com.mapbox.mapboxsdk.maps.NativeMapView.setZoom(NativeMapView.java:325)
        at com.mapbox.mapboxsdk.maps.Transform.setZoom(Transform.java:218)
        at com.mapbox.mapboxsdk.maps.MapGestureDetector$2.onAnimationUpdate(MapGestureDetector.java:814)
        at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1547)
        at android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1339)
        at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1471)
        at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
        at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
        at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1002)
        at android.view.Choreographer.doCallbacks(Choreographer.java:816)
        at android.view.Choreographer.doFrame(Choreographer.java:748)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:990)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6863)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Configuration

Android versions:
Device models:
Mapbox SDK versions: 7.2.0

    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.5.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.5.0'
@carstenhag
Copy link
Author

carstenhag commented Mar 27, 2019

I was looking through the release notes, and perhaps #14013 is related. Edit: Tried out the 7.3.0 Snapshot, but it's still broken.

This animation is causing multiple bugs for me. On another instances, panning does not work and only zooming keeps working, for no apparent reason and with no error in logcat.

@carstenhag
Copy link
Author

Any hint on when this gets available as snapshot? Just tried it out and my snapshot doesn't contain the new code yet. I also told gradle to refresh the dependencies.

@LukasPaczos
Copy link
Member

Gradle cache can be tricky. You can always try pointing to a specific snapshot artifact, for example

implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.4.0-20190402.124536-39' 

should contain the changes.

@LukasPaczos LukasPaczos added this to the release-m milestone Apr 2, 2019
@carstenhag
Copy link
Author

carstenhag commented Apr 2, 2019

Thanks a lot, got it now!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

No branches or pull requests

3 participants