react-native-vision-camera: πŸ› java.lang.NullPointerException in FrameProcessorRuntimeManager.

What were you trying to do?

We have 40k MAU and we see 230 occurrences of this error for the last 30 days.

Reproduceable Code

No response

What happened instead?

The issue seems to happen on app start.

Relevant log output

java.lang.NullPointerException: 
  at java.util.Objects.requireNonNull (Objects.java:245)
  at com.mrousavy.camera.frameprocessor.FrameProcessorRuntimeManager.<init> (FrameProcessorRuntimeManager.kt:33)
  at com.mrousavy.camera.CameraViewManager$1.run (CameraViewManager.kt:20)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:920)

Device

Android only: most seen on Google Pixel 4a, Google Pixel 6, Samsung Galaxy S20 FE 5G, Samsung Galaxy Z Flip3 5G, all have Android 12

VisionCamera Version

2.10.0

Additional information

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I attach the patch file here, if someone has the time to create a PR from it. But I guess since V3 is being worked on that PR might not be merged soon.

react-native-vision-camera+2.15.4.patch

diff --git a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt
index 7672b15..e6bab61 100644
--- a/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt
+++ b/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt
@@ -58,16 +58,6 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
     frameProcessorManager = null
   }
 
-  override fun initialize() {
-    super.initialize()
-
-    if (frameProcessorManager == null) {
-      frameProcessorThread.execute {
-        frameProcessorManager = FrameProcessorRuntimeManager(reactApplicationContext, frameProcessorThread)
-      }
-    }
-  }
-
   override fun onCatalystInstanceDestroy() {
     super.onCatalystInstanceDestroy()
     cleanup()
@@ -89,6 +79,21 @@ class CameraViewModule(reactContext: ReactApplicationContext) : ReactContextBase
     return view ?: throw ViewNotFoundError(viewId)
   }
 
+  @ReactMethod
+  fun installFrameProcessorBindings(): Boolean {
+    try {
+      if (frameProcessorManager == null) {
+        frameProcessorThread.execute {
+          frameProcessorManager = FrameProcessorRuntimeManager(reactApplicationContext, frameProcessorThread)
+        }
+      }
+      return true;
+    } catch (e: Error) {
+      Log.e(TAG, "Failed to install Frame Processor JSI Bindings!", e)
+      return false;
+    }
+  }
+
   @ReactMethod
   fun takePhoto(viewTag: Int, options: ReadableMap, promise: Promise) {
     coroutineScope.launch {
diff --git a/node_modules/react-native-vision-camera/lib/typescript/Camera.d.ts b/node_modules/react-native-vision-camera/lib/typescript/Camera.d.ts
index 7efd264..e9bc88e 100644
--- a/node_modules/react-native-vision-camera/lib/typescript/Camera.d.ts
+++ b/node_modules/react-native-vision-camera/lib/typescript/Camera.d.ts
@@ -48,6 +48,7 @@ export declare class Camera extends React.PureComponent<CameraProps> {
     /** @internal */
     constructor(props: CameraProps);
     private get handle();
+
     /**
      * Take a single photo and write it's content to a temporary file.
      *
diff --git a/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts b/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts
index 697872f..6d6b161 100644
--- a/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts
+++ b/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts
@@ -1,10 +1,16 @@
 /* global _setGlobalConsole */
 
 import { DependencyList, useCallback } from 'react';
+import { NativeModules, Platform } from 'react-native';
 import type { Frame } from '../Frame';
+const CameraModule = NativeModules.CameraView;
 
 type FrameProcessor = (frame: Frame) => void;
 
+if (Platform.OS === "android") {
+  CameraModule.installFrameProcessorBindings();
+}
+
 const capturableConsole = console;
 
 /**

I created a working patch that will fix this issue. Will create PR soon.

@pke any idea when do you will do a PR to fix?