当我在动画中触摸视图时 OSMDroid 崩溃

OSMDroid crashes when I touch the view while it's animating

当调用 mapController.animateTo 并且在动画仍在发生时有任何触摸事件时,我的应用程序崩溃了。这是我正在做的事情的精简版。但是这段代码也会崩溃。一开始我以为是mLocationOverlay.runOnFirstFix方法。但我发现我可以在任何地方调用它,它仍然会因 NullPointerException

而崩溃
   val ctx = applicationContext
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx))


    map = findViewById<View>(R.id.map) as MapView
    map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE)
    mapController = MapController(map)

    mLocationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(this), map)
    mLocationOverlay.enableMyLocation()
    mLocationOverlay.runOnFirstFix {
        runOnUiThread {
            mapController.animateTo(mLocationOverlay.myLocation, 14.0, 4000)
        }
    }
    map.overlays.add(mLocationOverlay)

E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.animation.Animator.cancel()' on a null object reference
        at org.osmdroid.views.MapController.stopAnimation(MapController.java:259)
        at org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay.disableFollowLocation(MyLocationNewOverlay.java:406)
        at org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay.onTouchEvent(MyLocationNewOverlay.java:301)
        at org.osmdroid.views.overlay.DefaultOverlayManager.onTouchEvent(DefaultOverlayManager.java:247)
        at org.osmdroid.views.MapView.dispatchTouchEvent(MapView.java:1123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:913)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1957)
        at android.app.Activity.dispatchTouchEvent(Activity.java:4182)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:871)
        at android.view.View.dispatchPointerEvent(View.java:15458)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:7457)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7233)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6595)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6786)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6843)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9880)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:9718)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:9671)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:10014)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:335)
        at android.os.Looper.loop(Looper.java:206)
        at android.app.ActivityThread.main(ActivityThread.java:8633)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.openmapskotlinexample, PID: 7652
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.animation.Animator.cancel()' on a null object reference
        at org.osmdroid.views.MapController.stopAnimation(MapController.java:259)
        at org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay.disableFollowLocation(MyLocationNewOverlay.java:406)
        at org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay.onTouchEvent(MyLocationNewOverlay.java:301)
        at org.osmdroid.views.overlay.DefaultOverlayManager.onTouchEvent(DefaultOverlayManager.java:247)
        at org.osmdroid.views.MapView.dispatchTouchEvent(MapView.java:1123)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3920)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:3535)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:913)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1957)
        at android.app.Activity.dispatchTouchEvent(Activity.java:4182)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:871)
        at android.view.View.dispatchPointerEvent(View.java:15458)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:7457)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7233)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6595)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6786)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6843)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9880)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:9718)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:9671)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:10014)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:335)
        at android.os.Looper.loop(Looper.java:206)
        at android.app.ActivityThread.main(ActivityThread.java:8633)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

当然,我一post这个问题就想通了。

mLocationOverlay.runOnFirstFix {
            runOnUiThread {
                mapView.controller.animateTo(mLocationOverlay.myLocation, 14.0, 4000)
                //mapController.animateTo(mLocationOverlay.myLocation, 14.0, 4000)
            }
        }

我必须通过 mapView 调用 animateTo 方法,而不是尝试直接从 MapController 调用它