react-native-gesture-handler icon indicating copy to clipboard operation
react-native-gesture-handler copied to clipboard

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

Open escowart opened this issue 4 years ago • 7 comments

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 avatar Oct 14 '21 16:10 escowart

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

escowart avatar Oct 14 '21 16:10 escowart

I have the same crash, any update?

RodolfoGS avatar Nov 18 '21 20:11 RodolfoGS

Having the same issue in production

andrecrimb avatar Mar 15 '22 08:03 andrecrimb

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

piaskowyk avatar Mar 31 '22 12:03 piaskowyk

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

RodolfoGS avatar Jun 23 '22 12:06 RodolfoGS

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}
      />

robwalkerco avatar Jul 18 '22 08:07 robwalkerco

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}
    />
  );
}

m-bert avatar Sep 22 '22 08:09 m-bert

any update on this? This issue still exists

urbanclap-admin avatar Feb 03 '23 14:02 urbanclap-admin

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

RodolfoGS avatar Feb 06 '23 16:02 RodolfoGS

@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

urbanclap-admin avatar Mar 01 '23 07:03 urbanclap-admin

@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

shivamp2404 avatar Mar 16 '23 09:03 shivamp2404

@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

j-piasecki avatar Jul 24 '23 12:07 j-piasecki

@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

dmregister avatar Jul 25 '23 17:07 dmregister

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

j-piasecki avatar Jul 26 '23 07:07 j-piasecki

Can anyone post the patch file?

SalaSuresh avatar Aug 09 '23 12:08 SalaSuresh

Thanks @j-piasecki

SalaSuresh avatar Aug 09 '23 14:08 SalaSuresh

@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

dmregister avatar Aug 18 '23 13:08 dmregister

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

RodolfoGS avatar Sep 10 '23 13:09 RodolfoGS

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

dmregister avatar Sep 12 '23 19:09 dmregister

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

RodolfoGS avatar Sep 12 '23 23:09 RodolfoGS

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)

bahinskamariia avatar Dec 06 '23 12:12 bahinskamariia