🐛 Crash in iOS release build when using SkiaFrameProcessor
What's happening?
I'm trying to use the Skia frame processor to draw a rectangle in the camera preview. However, my app crashes when I try to open the camera.
This only happens if I create a release build of my app and then download it via TestFlight. Everything works fine if I build directly to my device and then run the app using Expo.
Also, this issue seems to only occur when I'm using the SkiaFrameProcessor. If I change to useFrameProcessor and remove the Skia related code, then the app works fine.
Reproduceable Code
"react-native-worklets-core": "^1.3.3" "@shopify/react-native-skia": "1.3.4" "react-native-vision-camera": "4.3.2"
export default function App() {
const device = useCameraDevice("back");
const { hasPermission, requestPermission } = useCameraPermission();
const frameProcessor = useSkiaFrameProcessor(frame => {
"worklet";
frame.render();
const rect = Skia.XYWHRect(frame.width / 2, frame.height / 2, 150, 150);
const paint = Skia.Paint();
paint.setColor(Skia.Color("red"));
frame.drawRect(rect, paint);
}, []);
if (!hasPermission) {
requestPermission();
return <Text>No permission</Text>;
}
if (device == null) return <Text>No device</Text>;
return (
<Camera
style={{ flex: 1 }}
device={device}
isActive
frameProcessor={frameProcessor}
onError={e => console.error(e)}
outputOrientation="portrait"
/>
);
}
Relevant log output
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000016b677ff0
Exception Codes: 0x0000000000000002, 0x000000016b677ff0
VM Region Info: 0x16b677ff0 is in 0x16b674000-0x16b678000; bytes after start: 16368 bytes before end: 15
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
Stack 16b5ec000-16b674000 [ 544K] rw-/rwx SM=PRV thread 19
---> STACK GUARD 16b674000-16b678000 [ 16K] ---/rwx SM=NUL stack guard for thread 5
Stack 16b678000-16b700000 [ 544K] rw-/rwx SM=PRV thread 5
Termination Reason: SIGNAL 10 Bus error: 10
Terminating Process: exc handler [905]
Triggered by Thread: 5
Thread 5 name:
Thread 5 Crashed:
0 JavaScriptCore 0x00000001b0a15e1c JSC::initialize() + 8 (InitializeThreading.cpp:68)
1 JavaScriptCore 0x00000001b0023f60 JSStringCreateWithUTF8CString + 40 (JSStringRef.cpp:45)
2 MyApp 0x00000001050709fc 0x104ad4000 + 5884412
3 MyApp 0x00000001053284c0 0x104ad4000 + 8733888
4 MyApp 0x000000010533e9bc 0x104ad4000 + 8825276
5 MyApp 0x00000001053467dc 0x104ad4000 + 8857564
6 MyApp 0x00000001053459c4 0x104ad4000 + 8853956
7 MyApp 0x000000010533e928 0x104ad4000 + 8825128
8 MyApp 0x00000001053467dc 0x104ad4000 + 8857564
9 MyApp 0x00000001053459c4 0x104ad4000 + 8853956
10 MyApp 0x000000010533e928 0x104ad4000 + 8825128
11 MyApp 0x00000001053467dc 0x104ad4000 + 8857564
12 MyApp 0x00000001053459c4 0x104ad4000 + 8853956
13 MyApp 0x000000010533e928 0x104ad4000 + 8825128
14 MyApp 0x00000001053467dc 0x104ad4000 + 8857564
15 MyApp 0x00000001053459c4 0x104ad4000 + 8853956
16 MyApp 0x000000010533e928 0x104ad4000 + 8825128
17 MyApp 0x00000001053467dc 0x104ad4000 + 8857564
18 MyApp 0x00000001053459c4 0x104ad4000 + 8853956
19 MyApp 0x000000010533e928 0x104ad4000 + 8825128
20 MyApp 0x00000001053467dc 0x104ad4000 + 8857564
... repeats for 500 lines
Camera Device
{
"hasTorch": true,
"minZoom": 1,
"minFocusDistance": 12,
"sensorOrientation": "landscape-left",
"hardwareLevel": "full",
"maxExposure": 8,
"supportsLowLightBoost": false,
"physicalDevices": [
"wide-angle-camera"
],
"supportsFocus": true,
"supportsRawCapture": false,
"neutralZoom": 1,
"maxZoom": 16,
"hasFlash": true,
"minExposure": -8,
"name": "Back Camera",
"formats": [],
"isMultiCam": false,
"position": "back"
}
Device
iPad mini (6th generation) (iOS 17.5.1)
VisionCamera Version
4.3.2
Can you reproduce this issue in the VisionCamera Example app?
I didn't try (⚠️ your issue might get ignored & closed if you don't try this)
Additional information
- [X] I am using Expo
- [X] I have enabled Frame Processors (react-native-worklets-core)
- [X] I have read the Troubleshooting Guide
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar issues in this repository and found none.
Guten Tag, Hans here.
[!NOTE] New features, bugfixes, updates and other improvements are all handled mostly by
@mrousavyin his free time. To support@mrousavy, please consider 💖 sponsoring him on GitHub 💖. Sponsored issues will be prioritized.
Is there any updated on this issue?
+1
Any updates?
+1 Also having this issue.
It works with regular frame processor, but Skia frame processor (without any logic inside) crashes the app)
Any updates on this?
@mrousavy any chance you could take a look please?
Don't really have a lot of free time at the moment.
@tomerh2001 same happening with me, i'm trying to add color filters. Have you resolve the issue?
@tomerh2001 same happening with me, i'm trying to add color filters. Have you resolve the issue?
Unfortunately no, this had costed me a lot of time and in the end I just migrated back to an old working version, with the hope that @mrousavy would eventually have time to look at it.
The solution I tried to suggest before is actually a pretty shit one, tested it out and the drawings are pretty delayed, my bad. Realized this thread is for release and not development too.
Also experiencing crashing when it comes using vision-camera-resize-plugin on the latest Expo and VisionCamera versions, currently using the JavaScript resize function instead (that you gave here @mrousavy). But thank you so much for all the awesome work you've put into this ecosystem. That a measly React dev like me can have the opportunity to deliver an app using the latest AI models. It's a game-changer.
Edit: Nevermind, figured out the resize problem just by reading through issues, summarized it here.
+1. Anyone have any ideas as where to start looking for the issue? I'm not in production yet but will probably have to use the normal frame processor for ios and use the skia processor for android. I've noticed the skia processor seems to have a memory leak when I run it in android but not sure if that's related (I don't get the same behaviour with the normal processor).
any update?
+1