react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 [Android] Crash when calling toArrayBuffer

Open quocluongha opened this issue 7 months ago • 4 comments

What's happening?

I encounter this error when trying to call frame.toArrayBuffer() in frame processor on Android devices, it works fine on iOS though. Please inspect the logcat below.

I found out that this issue is also related to this error, but it was closed a long time ago. Maybe there was something changes to Android 15 API?

Reproduceable Code

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

    const arrayBuffer = frame.toArrayBuffer()

    console.log(arrayBuffer.byteLength)
  }, [])

Relevant log output

2025-05-26 00:26:56.911 10276-10340 Frame                   com.mrousavy.camera.example          I  Converting 1280 x 720 @ 1280 HardwareBuffer...
2025-05-26 00:26:56.911 10276-10340 .camera.example         com.mrousavy.camera.example          E  lockImpl:290 failed with 'Error3::BAD_VALUE'
2025-05-26 00:26:56.911 10276-10340 Gralloc3                com.mrousavy.camera.example          W  lock(0xb400006e6b06cf90, ...) failed: 3
2025-05-26 00:26:56.912 10276-10340 Frame                   com.mrousavy.camera.example          I  Converting 1280 x 720 @ 1280 HardwareBuffer...
2025-05-26 00:26:56.912 10276-10340 .camera.example         com.mrousavy.camera.example          E  lockImpl:290 failed with 'Error3::BAD_VALUE'
2025-05-26 00:26:56.912 10276-10340 Gralloc3                com.mrousavy.camera.example          W  lock(0xb400006e6b06d530, ...) failed: 3
2025-05-26 00:26:56.938 10276-10340 Frame                   com.mrousavy.camera.example          I  Converting 1280 x 720 @ 1280 HardwareBuffer...
2025-05-26 00:26:56.939 10276-10340 .camera.example         com.mrousavy.camera.example          E  lockImpl:290 failed with 'Error3::BAD_VALUE'
2025-05-26 00:26:56.939 10276-10340 Gralloc3                com.mrousavy.camera.example          W  lock(0xb400006e6b06d140, ...) failed: 3
2025-05-26 00:26:56.944 10276-10340 Frame                   com.mrousavy.camera.example          I  Converting 1280 x 720 @ 1280 HardwareBuffer...
2025-05-26 00:26:56.945 10276-10340 .camera.example         com.mrousavy.camera.example          E  lockImpl:290 failed with 'Error3::BAD_VALUE'
2025-05-26 00:26:56.945 10276-10340 Gralloc3                com.mrousavy.camera.example          W  lock(0xb400006e6b06e730, ...) failed: 3

Camera Device

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

Device

Android 15 emulator with Google Play Service

VisionCamera Version

4.6.4

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

quocluongha avatar May 25 '25 18:05 quocluongha

Guten Tag, Hans here 🍻

Looks like you provided helpful information and logs, which is good! Regarding your issue with frame.toArrayBuffer() on Android 15, I suggest checking if your environment is properly set up or if there are some configurations you might have missed. Since it's working on iOS, it could be specific to the Android implementation or the emulator's handling.

Please keep an eye on updates to see if this gets addressed. If you find a need for more detailed help, you might want to consider sponsoring the project here to get quicker responses. Let's keep this open for now!

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

maintenance-hans[bot] avatar May 25 '25 18:05 maintenance-hans[bot]

I have checked my environment and configurations, they are correctly set up. @mrousavy can you please have a look?

quocluongha avatar May 26 '25 03:05 quocluongha

I have the same issue @mrousavy

Romain-Boudot avatar Aug 03 '25 11:08 Romain-Boudot

Seems device specific.

Samsung Galaxy S25, Android 15: ❌ crashes Samsung A36, Android 15: ❌ crashes Samsung Galaxy S24 FE, Android 15: 🟢 works as expected Samsung S20, Android 13: 🟢 works as expected

Temporary workaround is to wrap calls with a try catch

try {
  const buffer = frame.toArrayBuffer();

  // do processing on buffer

} catch (err) {
 // handle devices that throw, so app doesn't crash
}
GPU
samsung a36 Adreno 710
samsung galaxy s25 Adreno 830
samsung galaxy s24 fe Xclipse 940
Samsung S20 FE 5g Adreno 650

From logcat

2025-10-20 10:23:32.993 22236-22395 Frame com.sample.app I Converting 1280 x 720 @ 1280 HardwareBuffer... 2025-10-20 10:23:32.994 22236-22395 SnapAlloc com.sample.app E Lock failed - CPU can't access 2025-10-20 10:23:32.994 22236-22395 qdgralloc com.sample.app E Lock: Failed to lock via SnapAlloc. Error code: 3 2025-10-20 10:23:32.994 22236-22395 qdgralloc com.sample.app E Snap failed to lock buffer 2025-10-20 10:23:32.994 22236-22395 Gralloc5 com.sample.app W lock(0x792c522350, ...) failed: 3

andrew-schenk avatar Oct 20 '25 15:10 andrew-schenk