mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.28k stars 1.07k forks source link

🐛 In production, runAsync does not work inside a useSkiaFrameProcessor #3123

Open pepperav opened 1 month ago

pepperav commented 1 month ago

What's happening?

Hello, I found that, in production (with TestFlight for iOS or downloading the signed Android bundle), the code inside myWorklet will never be called (it works at develop time):

const frameProcessor = useSkiaFrameProcessor((frame) => {
 'worklet'

  frame.render();

  runAsync(frame, () => {
    'worklet'

    // Do something with heavy ML frame processor plugin

    myWorklet(frame);
  })
}, [ myWorklet ]);

const myWorklet = Worklets.createRunOnJS((frame: Frame) => {
   // Do something here...
}

Instead, using runAtTargetFps it works:

const frameProcessor = useSkiaFrameProcessor((frame) => {
 'worklet'

  frame.render();

  runAtTargetFps(2, () => {
    'worklet'

    // Do something with heavy ML frame processor plugin

    myWorklet(frame);
  })
}, [ myWorklet ]);

const myWorklet = Worklets.createRunOnJS((frame: Frame) => {
   // Do something here...
}

Here the package.json

"dependencies": {
  "@shopify/react-native-skia": "1.3.10",
  "expo": "~51.0.18",
  "react": "18.2.0",
  "react-native": "0.74.4",
  "react-native-reanimated": "~3.14.0",
  "react-native-vision-camera": "^4.5.1",
  "react-native-worklets-core": "^1.3.3"
},
"devDependencies": {
  "@babel/core": "^7.20.0",
  "@types/react": "~18.2.14",
  "typescript": "~5.3.3"
}

Reproduceable Code

const frameProcessor = useSkiaFrameProcessor((frame) => {
 'worklet'

  frame.render();

  runAsync(frame, () => {
    'worklet'

    // Do something with heavy ML frame processor plugin

    myWorklet(frame);
  })
}, [ myWorklet ]);

const myWorklet = Worklets.createRunOnJS((frame: Frame) => {
   // Do something here...
}

Relevant log output

--------- beginning of main
2024-08-06 10:03:21.435 20304-20304 VisionCameraProxy       com.giuseppe.ravida.appname       D  Finding view 1295...
2024-08-06 10:03:21.435 20304-20304 VisionCameraProxy       com.giuseppe.ravida.appname       D  Found view 1295!
2024-08-06 10:03:21.448 20304-20304 VisionCameraProxy       com.giuseppe.ravida.appname       D  Finding view 1295...
2024-08-06 10:03:21.448 20304-20304 VisionCameraProxy       com.giuseppe.ravida.appname       D  Found view 1295!
2024-08-06 10:03:22.534 20304-20304 VisionCameraProxy       com.giuseppe.ravida.appname       D  Finding view 1295...
2024-08-06 10:03:22.534 20304-20304 VisionCameraProxy       com.giuseppe.ravida.appname       D  Found view 1295!

Camera Device

{
  "formats": [],
  "sensorOrientation": "landscape-left",
  "hardwareLevel": "full",
  "maxZoom": 8,
  "minZoom": 1,
  "maxExposure": 24,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "minFocusDistance": 0,
  "minExposure": -24,
  "name": "0 (BACK) androidx.camera.camera2",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

iPhone 8 plus, iPhone 15 Pro Max, Redmi Note 7

VisionCamera Version

4.5.1

Can you reproduce this issue in the VisionCamera Example app?

No, I cannot reproduce the issue in the Example app

Additional information

maintenance-hans[bot] commented 1 month ago

Guten Tag, Hans here! 🍻

Thank you for your detailed report! It looks like you are facing issues with runAsync within useSkiaFrameProcessor only in production builds. However, I notice you did not provide logs from the production environment that would help in diagnosing this problem. Please ensure to gather and share the relevant logs using Xcode or adb logcat, as this will greatly assist mrousavy in troubleshooting.

Additionally, have you confirmed you followed all instructions in the Troubleshooting Guide? Keep us updated, so we can help you further!

Note: If you think I made a mistake, please ping @mrousavy to take a look.