react-native-gesture-handler: IllegalArgumentException pointerCount must be at least 1
Description
Crash reported by our crash analytics tool. Reason is unknown, but this library shows in the stack trace.
Screenshots
Stack trace:
java.lang.IllegalArgumentException pointerCount must be at least 1 
    MotionEvent.java:-2 android.view.MotionEvent.nativeInitialize
    MotionEvent.java:1706 android.view.MotionEvent.obtain
    MotionEvent.java:1752 android.view.MotionEvent.obtain
    GestureHandler.java:270 com.swmansion.gesturehandler.GestureHandler.adaptEvent
    GestureHandler.java:295 com.swmansion.gesturehandler.GestureHandler.handle
    GestureHandlerOrchestrator.java:301 com.swmansion.gesturehandler.GestureHandlerOrchestrator.deliverEventToGestureHandler
    GestureHandlerOrchestrator.java:259 com.swmansion.gesturehandler.GestureHandlerOrchestrator.deliverEventToGestureHandlers
    GestureHandlerOrchestrator.java:101 com.swmansion.gesturehandler.GestureHandlerOrchestrator.onTouchEvent
    RNGestureHandlerRootHelper.java:126 com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent
    RNGestureHandlerEnabledRootView.java:36 com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView.dispatchTouchEvent
    ViewGroup.java:3142 android.view.ViewGroup.dispatchTransformedTouchEvent
    ViewGroup.java:2834 android.view.ViewGroup.dispatchTouchEvent
    ViewGroup.java:3142 android.view.ViewGroup.dispatchTransformedTouchEvent
    ViewGroup.java:2834 android.view.ViewGroup.dispatchTouchEvent
    ViewGroup.java:3142 android.view.ViewGroup.dispatchTransformedTouchEvent
    ViewGroup.java:2834 android.view.ViewGroup.dispatchTouchEvent
    ViewGroup.java:3142 android.view.ViewGroup.dispatchTransformedTouchEvent
    ViewGroup.java:2834 android.view.ViewGroup.dispatchTouchEvent
    ViewGroup.java:3142 android.view.ViewGroup.dispatchTransformedTouchEvent
    ViewGroup.java:2834 android.view.ViewGroup.dispatchTouchEvent
    DecorView.java:495 com.android.internal.policy.DecorView.superDispatchTouchEvent
    PhoneWindow.java:1868 com.android.internal.policy.PhoneWindow.superDispatchTouchEvent
    Activity.java:4022 android.app.Activity.dispatchTouchEvent
    WindowCallbackWrapper.java:69 androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent
    DecorView.java:453 com.android.internal.policy.DecorView.dispatchTouchEvent
    View.java:14261 android.view.View.dispatchPointerEvent
    ViewRootImpl.java:5903 android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent
    ViewRootImpl.java:5706 android.view.ViewRootImpl$ViewPostImeInputStage.onProcess
    ViewRootImpl.java:5153 android.view.ViewRootImpl$InputStage.deliver
    ViewRootImpl.java:5206 android.view.ViewRootImpl$InputStage.onDeliverToNext
    ViewRootImpl.java:5172 android.view.ViewRootImpl$InputStage.forward
    ViewRootImpl.java:5180 android.view.ViewRootImpl$InputStage.apply
    ViewRootImpl.java:5153 android.view.ViewRootImpl$InputStage.deliver
    ViewRootImpl.java:5206 android.view.ViewRootImpl$InputStage.onDeliverToNext
    ViewRootImpl.java:5172 android.view.ViewRootImpl$InputStage.forward
    ViewRootImpl.java:5328 android.view.ViewRootImpl$AsyncInputStage.forward
    ViewRootImpl.java:5180 android.view.ViewRootImpl$InputStage.apply
    ViewRootImpl.java:5385 android.view.ViewRootImpl$AsyncInputStage.apply
    ViewRootImpl.java:5153 android.view.ViewRootImpl$InputStage.deliver
    ViewRootImpl.java:5206 android.view.ViewRootImpl$InputStage.onDeliverToNext
    ViewRootImpl.java:5172 android.view.ViewRootImpl$InputStage.forward
    ViewRootImpl.java:5180 android.view.ViewRootImpl$InputStage.apply
    ViewRootImpl.java:5153 android.view.ViewRootImpl$InputStage.deliver
    ViewRootImpl.java:8002 android.view.ViewRootImpl.deliverInputEvent
    ViewRootImpl.java:7969 android.view.ViewRootImpl.doProcessInputEvents
    ViewRootImpl.java:7930 android.view.ViewRootImpl.enqueueInputEvent
    ViewRootImpl.java:8156 android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent
    InputEventReceiver.java:189 android.view.InputEventReceiver.dispatchInputEvent
    InputEventReceiver.java:-2 android.view.InputEventReceiver.nativeConsumeBatchedInputEvents
    InputEventReceiver.java:179 android.view.InputEventReceiver.consumeBatchedInputEvents
    ViewRootImpl.java:8086 android.view.ViewRootImpl.doConsumeBatchedInput
    ViewRootImpl.java:8180 android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run
    Choreographer.java:1043 android.view.Choreographer$CallbackRecord.run
    Choreographer.java:866 android.view.Choreographer.doCallbacks
    Choreographer.java:794 android.view.Choreographer.doFrame
    Choreographer.java:1028 android.view.Choreographer$FrameDisplayEventReceiver.run
    Handler.java:883 android.os.Handler.handleCallback
    Handler.java:100 android.os.Handler.dispatchMessage
    Looper.java:214 android.os.Looper.loop
    ActivityThread.java:7615 android.app.ActivityThread.main
    Method.java:-2 java.lang.reflect.Method.invoke
    RuntimeInit.java:492 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run
    ZygoteInit.java:964 com.android.internal.os.ZygoteInit.main
Steps To Reproduce
Expected behavior
No crash.
Actual behavior
Random crash
Snack or minimal code example
I’m not using the library directly, but rather react-navigation is using it. However, the following code is used for initialization:
index.js
import 'react-native-gesture-handler';
... other imports and index code
MainActivity.java (as documented in the installation guide)
    /**
    For react-native-gesture-handler (used)
    */
    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, getMainComponentName()) {
            @Override
            protected ReactRootView createRootView() {
                return new RNGestureHandlerEnabledRootView(MainActivity.this);
            }
        };
    }
Package versions
- React: 16.13.1
 - React Native: 0.62.2
 - React Native Gesture Handler: 1.8.0
 - @react-navigation/compat: 5.2.5
 - @react-navigation/native: 5.7.3
 - @react-navigation/stack: 5.9.0
 - Android: 10 (LG Stylo 6 (LM-Q730))
 
About this issue
- Original URL
 - State: closed
 - Created 4 years ago
 - Reactions: 9
 - Comments: 24 (5 by maintainers)
 
Commits related to this issue
- Add AdaptEventException (#1685) Add AdaptEventException to get more info about #1188. When the IllegalArgumentException from the linked issue is thrown it will be caught and rethrown wrapped in Adap... — committed to software-mansion/react-native-gesture-handler by j-piasecki 3 years ago
 - Add AdaptEventException (#1685) Add AdaptEventException to get more info about #1188. When the IllegalArgumentException from the linked issue is thrown it will be caught and rethrown wrapped in Adap... — committed to wordpress-mobile/react-native-gesture-handler by j-piasecki 3 years ago
 - Add a workaround for `pointerCount must be at least 1` (#1982) Fixes https://github.com/software-mansion/react-native-gesture-handler/issues/1188. As @kmagiera suggested in https://github.com/soft... — committed to software-mansion/react-native-gesture-handler by j-piasecki 2 years ago
 
I’d be ok with merging a change that mitigates the issue. Seems like there are many people reporting it and no way for us to get a repro. Would suggest to make it so that it still crashes in DEV but not in PROD, this way there is still possibility for us to discover the reason of the crash in the future. Will defer to @j-piasecki for the final resolution
Hi!
You can fix this by adding
if (count == 0) return event; // Avoid crash in MotionEvent.obtain when count = 0before
In
GestureHandler.java,private MotionEvent adaptEvent(MotionEvent event), line 284.You can use attached patch with patch-package: Just follow setup instructions, unzip attached file and copy into Your project
patchesfolder (create one if needed).react-native-gesture-handler+1.10.3.patch.zip
YES. But we prefer misbehavior than a crash.
Hi @j-piasecki, I have errors with the logs that you implemented in https://github.com/software-mansion/react-native-gesture-handler/pull/1685
I share you 3 logs from different users/devices
react-native: 0.64.2react-native-gesture-handler: 2.0.0Android: 9 3705A
Android: 10 TBD
view,orchestratorandtrackedPointershave changesAndroid: 10 Stylo 6
view,orchestratorandtrackedPointershave changesI have the same issue for a while now, currently my app is using version 1.8.0, and according to the logs the majority of the crashes are happening on a screen with a mapview (react-native-maps) and on LG stylo devices, the app does not have any custom gesture handlers, we use it because of react-navigation.
I tried debugging this one for a bit and I didn’t found much. What we know for sure: this bug is caused by array
mTrackedPointerIDsbeing reset – we don’t track pointers for the gesture handler when the event generated by it arrives.