software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
5.85k stars 954 forks source link

Android Crash: Fatal Exception: java.lang.IllegalArgumentException: pointerIndex out of range #1679

Closed escowart closed 7 months ago

escowart commented 2 years ago

Description

Fatal Exception: java.lang.IllegalArgumentException: pointerIndex out of range
       at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java)
       at android.view.MotionEvent.getY(MotionEvent.java:2416)
       at android.widget.ScrollView.onTouchEvent(ScrollView.java:866)
       at com.facebook.react.views.scroll.ReactScrollView.onTouchEvent(ReactScrollView.java:323)
       at android.view.View.dispatchTouchEvent(View.java:14309)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3112)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2785)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:66)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
       at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:488)
       at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1871)
       at android.app.Activity.dispatchTouchEvent(Activity.java:4125)
       at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
       at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:446)
       at android.view.View.dispatchPointerEvent(View.java:14568)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6022)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5825)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5316)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5491)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5548)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5373)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5339)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5347)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5320)
       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8086)
       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8037)
       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7998)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8209)
       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:335)
       at android.os.Looper.loop(Looper.java:183)
       at android.app.ActivityThread.main(ActivityThread.java:7660)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Steps To Reproduce

Unknown

Expected behavior

Graceful error handling

Actual behavior

Crash

Package versions

"react": "~17.0.2",
"react-native": "~0.66.0",
"react-native-gesture-handler": "~1.10.3",
escowart commented 2 years ago

React Native Issue: https://github.com/facebook/react-native/issues/30320

RodolfoGS commented 2 years ago

I have the same crash, any update?

andrecrimb commented 2 years ago

Having the same issue in production

piaskowyk commented 2 years ago

Sorry for the delay, but we still want to fix it.

RodolfoGS commented 1 year ago

I still having this issue in react-native-gesture-handler: 2.4.2, any update?

Here are a patch but I don't know if this could generate another issue.

https://github.com/facebook/react-native/issues/30320#issuecomment-875476422

robwalkerco commented 1 year ago

I could replicate this crash on the following component by starting a pull-to-refresh with one finger, then adding a second finger during the pull -

The patch at https://github.com/facebook/react-native/issues/30320#issuecomment-875476422 did prevent the crash for me :)

import {
  RefreshControl as RNRefreshControl,
  RefreshControlProps,
} from 'react-native';
import { FlatList as GestureHandlerFlatList } from 'react-native-gesture-handler';

const ReanimatedFlatList = Animated.createAnimatedComponent(
  GestureHandlerFlatList,
);

const RefreshControl = createNativeWrapper(RNRefreshControl);

const CustomRefreshControl = (props: RefreshControlProps) => (
  <RefreshControl {...props} />
);

...

<ReanimatedFlatList
        ref={flatListRef}
        onScroll={scrollHandler}
        onLayout={(evt: LayoutChangeEvent) => {
          listShellHeight.value = evt.nativeEvent.layout.height;
          if (typeof props.onLayout === 'function') {
            props.onLayout?.(evt);
          }
        }}
        refreshControl={
          <CustomRefreshControl
            refreshing={Boolean(props?.refreshing)}
            progressViewOffset={Number(props?.progressViewOffset ?? 0)}
            onRefresh={() => {
              setRefreshCount(val => val + 1);
              if (typeof onRefresh === 'function') {
                onRefresh();
              }
            }}
          />
        }
        {...props}
      />
m-bert commented 1 year ago

Hi @robwalkerco 👋 I tried to reproduce the issue by completing the code you've provided. Unfortunately I was unable to do that. Could you please provide repro so that we can look further into this problem? Code below is the code I used, since some of the methods in yours are missing.

import React, { useState } from 'react';

import {
  RefreshControl as RNRefreshControl,
  RefreshControlProps,
} from 'react-native';
import {
  createNativeWrapper,
  FlatList as GestureHandlerFlatList,
} from 'react-native-gesture-handler';
import Animated from 'react-native-reanimated';

export default function App() {
  const ReanimatedFlatList = Animated.createAnimatedComponent(
    GestureHandlerFlatList
  );

  const RefreshControl = createNativeWrapper(RNRefreshControl);

  const CustomRefreshControl = (props: RefreshControlProps) => (
    <RefreshControl {...props} />
  );

  const [refreshCount, setRefreshCount] = useState(0);

  const onScroll = () => {
    console.log(refreshCount);
  };

  const onRefresh = () => {
    console.log(refreshCount);
  };

  const onLayout = (e) => {
    console.log(e);
  };

  return (
    <ReanimatedFlatList
      onScroll={onScroll}
      onLayout={onLayout}
      refreshControl={
        <CustomRefreshControl
          refreshing={false}
          progressViewOffset={0}
          onRefresh={() => {
            setRefreshCount((val) => val + 1);
            onRefresh();
          }}
        />
      }
      data={undefined}
      renderItem={undefined}
    />
  );
}
urbanclap-admin commented 1 year ago

any update on this? This issue still exists

RodolfoGS commented 1 year ago

@urbanclap-admin I'm using this patch and it works good. https://github.com/facebook/react-native/issues/30320#issuecomment-1170113452

urbanclap-admin commented 1 year ago

@urbanclap-admin I'm using this patch and it works good. facebook/react-native#30320 (comment)

started getting this crash -> https://github.com/software-mansion/react-native-gesture-handler/issues/1188 after using the above patch you mentioned

shivamp2404 commented 1 year ago

@j-piasecki @piaskowyk

import {Modal, StyleSheet, Text, Pressable, View, FlatList, Dimensions} from 'react-native';
import Animated from 'react-native-reanimated';
import { GestureHandlerRootView, NativeViewGestureHandler } from "react-native-gesture-handler";
const DATA = []
for (let i=0;i<100;i++){
  DATA.push({id:i, title:`hello - ${i}`})
}
const windowHeight = Dimensions.get('window').height;
const App = () => {
  const [modalVisible, setModalVisible] = useState(false);

  const Item = ({title}) => (
    <View style={styles.item}>
      <Text style={styles.title}>{title}</Text>
    </View>
  );

  return (
    <View style={styles.centeredView}>
      <Modal
        animationType="slide"
        transparent={true}
        visible={modalVisible}
      >
        <GestureHandlerRootView
        style={{
            width: '100%',
            height: '100%'
          }}
    >
          <Animated.View
            style={
              {
                backgroundColor: 'white',
                overflow: 'hidden',
                flexShrink: 1,
                width: '100%',
                opacity: 1,

                height: windowHeight/2
            }}
          >
              <NativeViewGestureHandler>
                <FlatList
                  data={DATA}
                  renderItem={({item}) => <Item title={item.title} />}
                  keyExtractor={item => item.id}
                />
              </NativeViewGestureHandler>
          </Animated.View>

</GestureHandlerRootView>
      </Modal>
      <Pressable
        style={[styles.button, styles.buttonOpen]}
        onPress={() => setModalVisible(true)}>
        <Text style={styles.textStyle}>Show Modal</Text>
      </Pressable>
    </View>
  );
};

const styles = StyleSheet.create({
  centeredView: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    marginTop: 22,
  },

  button: {
    borderRadius: 20,
    padding: 10,
    elevation: 2,
  },
  buttonOpen: {
    backgroundColor: '#F194FF',
  },
  textStyle: {
    color: 'white',
    fontWeight: 'bold',
    textAlign: 'center',
  },
  title:{
    backgroundColor:'black'
  }
});

export default App

Use the above code example to repro the issue.

Steps to repro: scroll the list and when the finger is on the list, try to scroll below the Modal when both the fingers are on screen, lift the first finger that was on the list, and the app will crash

https://user-images.githubusercontent.com/119509177/225569611-5a2206df-8322-4849-80fe-26756bd287de.mp4

j-piasecki commented 9 months ago

@shivamp2404 Thanks for the repro ❤️! Could you check if this PR: https://github.com/software-mansion/react-native-gesture-handler/pull/2551 solves the problem for you (and doesn't break anything else)?

cc. @RodolfoGS

dmregister commented 9 months ago

@j-piasecki we also see quite a bit of these errors in our app. Short of use patching the package with your changes, is there a pre-release version we could use? What are the chances these changes are published as a version in the near future?

Thanks again for helping out here

j-piasecki commented 9 months ago

@dmregister There's no pre-release version with it 😞. The two options for using it right now are using patch-package or installing Gesture Handler directly from the branch this PR is based on.

I would like to get confirmation that this PR actually fixes the underlying issues before merging & releasing. While the repro above no longer crashes, the full use case may be more complicated. Would it be possible for you to check it in your application?

SalaSuresh commented 9 months ago

Can anyone post the patch file?

j-piasecki commented 9 months ago

react-native-gesture-handler+2.12.0.patch

SalaSuresh commented 9 months ago

Thanks @j-piasecki

dmregister commented 9 months ago

@j-piasecki we deployed a patch into production and it seems like this has addressed the issue. The version deployed with the fix is only experiencing a few errors compared to over a thousand from previous versions.

Thanks again for all the hard work and support!

Screenshot 2023-08-18 at 9 32 46 AM

RodolfoGS commented 8 months ago

@dmregister how is it going with that patch? Are the crashes gone? You applied the last patch of @ j-piasecki, right? (https://github.com/software-mansion/react-native-gesture-handler/pull/2551)

dmregister commented 8 months ago

@RodolfoGS yes the crashes are gone and we have not see any other side effects from this patch.

We upgraded to the latest version and applied the patch from that PR.

RodolfoGS commented 8 months ago

@dmregister awesome, thank you so much for your feedback! @j-piasecki looks like your PR is working! Thank you for fixing it

bahinskamariia commented 5 months ago

Issue still reproducible. This patch already merged as a changes to new version.

react-native-gesture-handler+2.12.0.patch

Version react-native-gesture-handler

2.13.4

Stacktrace:

java.lang.IllegalArgumentException: pointerIndex out of range at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java) at android.view.MotionEvent.getY(MotionEvent.java:2445) at android.widget.ScrollView.onTouchEvent(ScrollView.java:895) at com.facebook.react.views.scroll.ReactScrollView.onTouchEvent(ReactScrollView.java:460) at com.swmansion.gesturehandler.core.NativeViewGestureHandler.onHandle(NativeViewGestureHandler.java:113) at com.swmansion.gesturehandler.core.GestureHandler.handle(GestureHandler.java:374) at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.deliverEventToGestureHandler(GestureHandlerOrchestrator.java:276) at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.deliverEventToGestureHandlers(GestureHandlerOrchestrator.java:231) at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.onTouchEvent(GestureHandlerOrchestrator.java:45) at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.dispatchTouchEvent(RNGestureHandlerRootHelper.java:97) at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.java:35) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3173) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2823) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:502) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1890) at android.app.Activity.dispatchTouchEvent(Activity.java:4195) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70) at com.dynatrace.android.window.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:79) at com.contentsquare.android.sdk.cf.dispatchTouchEvent(cf.java:4) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:460) at android.view.View.dispatchPointerEvent(View.java:14837) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6617) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6392) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5866) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5923) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5889) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6054) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5897) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6111) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5870) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5923) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5889) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5897) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5870) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8931) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8871) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8828) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9063) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:259) at android.os.MessageQueue.nativePollOnce(MessageQueue.java) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loopOnce(Looper.java:161) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7888) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)