gre / react-native-view-shot

Snapshot a React Native view and save it to an image
https://github.com/gre/react-native-view-shot-example
MIT License
2.64k stars 344 forks source link

NullPointerException in applyTransformations #488

Open gavrilikhin-d opened 1 year ago

gavrilikhin-d commented 1 year ago

bug report

When using handleGLSurfaceViewOnAndroid: true there is a non-frequent bug that crashes our app. This code in applyTransformations throws NullPointerException:

// find all parents of the child view
View iterator = child;
do {
      ms.add(iterator);

      iterator = (View) iterator.getParent(); // This line throws
} while (iterator != root);

My guess is that iterator == root on first iteration, because there is a special case in getAllChildren, where view is a children of itself:

@NonNull
private List<View> getAllChildren(@NonNull final View v) {
        if (!(v instanceof ViewGroup)) {
            final ArrayList<View> viewArrayList = new ArrayList<>();
            viewArrayList.add(v);

            return viewArrayList;
        }
     // ...
    }

Version & Platform

mobile@2.3.0 /Users/gavrilikhin_d/Code/chatroulette/app/mobile
├─┬ @react-native-async-storage/async-storage@1.17.11
│ └── react-native@0.71.4 deduped
├─┬ @react-native-firebase/app@18.3.0
│ └── react-native@0.71.4 deduped
├─┬ @react-native-google-signin/google-signin@8.2.2
│ └── react-native@0.71.4 deduped
├─┬ @react-navigation/bottom-tabs@6.5.7
│ ├─┬ @react-navigation/elements@1.3.17
│ │ └── react-native@0.71.4 deduped
│ └── react-native@0.71.4 deduped
├─┬ @react-navigation/native@6.1.6
│ └── react-native@0.71.4 deduped
├─┬ @react-navigation/stack@6.3.16
│ └── react-native@0.71.4 deduped
├─┬ @sentry/react-native@5.1.1
│ └── react-native@0.71.4 deduped
├─┬ @stripe/stripe-react-native@0.22.1
│ └── react-native@0.71.4 deduped
├─┬ @testing-library/react-native@12.1.2
│ └── react-native@0.71.4 deduped
├─┬ @voximplant/react-native-foreground-service@3.0.2
│ └── react-native@0.71.4 deduped
├─┬ lottie-react-native@5.1.5
│ ├─┬ react-native-safe-modules@1.0.3
│ │ └── react-native@0.71.4 deduped
│ └── react-native@0.71.4 deduped
├─┬ react-native-exception-handler@2.10.10
│ └── react-native@0.71.4 deduped
├─┬ react-native-fbsdk-next@11.1.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-file-access@2.5.3
│ └── react-native@0.71.4 deduped
├─┬ react-native-gesture-handler@2.9.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-get-random-values@1.8.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-iap@12.10.5
│ └── react-native@0.71.4 deduped
├─┬ react-native-incall-manager@4.0.1 (git+ssh://git@github.com/react-native-webrtc/react-native-incall-manager.git#e66e99bc49c0ac859844a4d3f1b6214414c76d2a)
│ └── react-native@0.71.4 deduped
├─┬ react-native-localize@2.2.6
│ └── react-native@0.71.4 deduped
├─┬ react-native-modal@13.0.1
│ └── react-native@0.71.4 deduped
├─┬ react-native-safe-area-context@4.5.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-screens@3.20.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-svg-transformer@1.0.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-svg@13.8.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-view-shot@3.7.0
│ └── react-native@0.71.4 deduped
├─┬ react-native-webrtc@111.0.3
│ └── react-native@0.71.4 deduped
├─┬ react-native-webview@11.26.1
│ └── react-native@0.71.4 deduped
├── react-native@0.71.4
└─┬ react-redux@8.0.5
  └── react-native@0.71.4 deduped

Platform: Android

Expected behavior

No crash

Actual behavior

Crash

Steps to reproduce the behavior

Couldn't find a way to reproduce