react-native-skia icon indicating copy to clipboard operation
react-native-skia copied to clipboard

Different Issues (Android and iOS) with useSkiaFrameProcessor

Open maxximee opened this issue 1 year ago • 31 comments

Description

Android Samsung S8 with android 9: Exception: ERROR Frame Processor Error: Exception in HostFunction: Failed to convert NativeBuffer to SkImage!, js engine: VisionCamera

Some other devices, for example Pixel 9 with android 15: Black Screen: Image

iOS Memory Leak, memory increase until app crashes: https://youtube.com/shorts/kShery3nVW0

React Native Skia Version

1.11.7

React Native Version

0.76.7

Using New Architecture

  • [x] Enabled

Steps to Reproduce

Start sample app linked below, just add useSkiaFrameProcessor to vision-camera. Relevant dependencies: "react-native-vision-camera": "4.6.3" "react-native-worklets-core": "1.5.0"

Snack, Code Example, Screenshot, or Link to Repository

https://github.com/maxximee/skiaIssues

    const frameProcessor = useSkiaFrameProcessor((frame) => {
        'worklet';
        frame.render();
    }, []);
    return (
        <Camera
            style={StyleSheet.absoluteFill}
            device={device}
            isActive={true}
            frameProcessor={frameProcessor}
        />
    );

maxximee avatar Feb 17 '25 04:02 maxximee

Note 1 : the sample repo only shows the crash and black screen on Android, it doesn't include the iOS yet. I'll add the ios build later, but I can reproduce the memory leak with my productive app. The iOS bug appeared in skia "1.11.x", it's working fine with "1.10.2",

Note 2 : Same result on android and ios with "newArchEnabled"

maxximee avatar Feb 17 '25 04:02 maxximee

Having the same issue, memory leak on ios

AilsonFreire avatar Mar 13 '25 17:03 AilsonFreire

I downgraded to "1.2.1" version, no crashes

AilsonFreire avatar Mar 13 '25 17:03 AilsonFreire

Tested on Android, getting black screen

AilsonFreire avatar Mar 15 '25 17:03 AilsonFreire

I'm experiencing the same iOS memory leak leading to a crash when using useSkiaFrameProcessor react-native: 0.76.7 @shopify/react-native-skia: 1.12.3

cgray9 avatar Apr 02 '25 04:04 cgray9

@wcandillon Hi William, sorry to @ you directly. I was wondering if those issues are on the radar, to me it sounds like pretty major issues with the skiaFrameProcessor (the ios memory leak causing a crash and some android devices not working at all crash | black screen).

maxximee avatar Apr 15 '25 03:04 maxximee

@maxximee we do plan do to maybe add an skia-frame-processor example and investigate this further but this will take a bit of time.

wcandillon avatar Apr 15 '25 11:04 wcandillon

Just tried updating to the new SDK version; still the same thing: there's a leak somewhere... 🤔

rafaelrcamargo avatar May 01 '25 22:05 rafaelrcamargo

Got a timelapse of the memory profile running on a physical device through Xcode, this with this minimal useSkiaFrameProcessor example:

Image

https://github.com/user-attachments/assets/b67170c5-5772-49c1-84f7-e6ba5ef79461

rafaelrcamargo avatar May 08 '25 03:05 rafaelrcamargo

Is there any update on this issue? There is still a breaking bug in useSkiaFrameProcessor on both iOS and most Android versions.

maxximee avatar Aug 08 '25 04:08 maxximee

Still experiencing the leak with react-native-vision-camera :(

toby-j avatar Aug 24 '25 10:08 toby-j

Just to add some details: The app works as expected on Android 13, but when running on Android 15, it breaks. If anyone has encountered similar issues with Android 15 or has suggestions for troubleshooting, I’d appreciate any guidance.

YOEL311 avatar Aug 25 '25 06:08 YOEL311

I'm experiencing the same iOS memory leak leading to a crash when using useSkiaFrameProcessor react-native: 0.77.2 @shopify/react-native-skia: 1.12.4

tehseenakhtar-fareye avatar Sep 01 '25 07:09 tehseenakhtar-fareye

"@shopify/react-native-skia": "v2.0.0-next.4",
"react-native-worklets-core": "^1.6.2",
"react-native-vision-camera": "^4.7.1",

I'm experiencing the same issue using useSkiaFrameProcessor. It was working until mysteriously, it stopped working. Copy/pasting my comment from https://github.com/mrousavy/react-native-vision-camera/issues/3606

There's some very strange behaviour going on. I have a complex skia-processor that was working flawlessly. Then I changed some arbitrary code unrelated to the frame processing and it started crashing with the same behaviour as @abs007 describes.

The mind boggling issue for me is that even after I remove the code and revert back to code that was working without issue before, it still crashes. I've tried:

  • npx expo prebuild --clean
  • removing the app from the device (I'm running on a physical device using npx expo ios --device)

The app starts working again after I remove the useSkiaProcessor hook. Even with a callback that simply renders the frame, it still crashes. Again, previously it was working flawlessly.

Right now I can't get it back to a working state. It's like the development build itself gets stuck in a malloc loop.

toonverbeek avatar Sep 03 '25 13:09 toonverbeek

Looks like with latest Skia update the ios memory leak issues might have been fix, I'll check soon. Android issues still there, useSkiaProcessor is not usable on Android (crashes or black screen on about 10% of devices). To reproduce, still same as in original issue description:

 const frameProcessor = useSkiaFrameProcessor((frame) => {
        'worklet';
        frame.render();
    }, []);
 const frameProcessor = useSkiaFrameProcessor((frame) => {
        'worklet';
        frame.render();
    }, []);
    return (
        <Camera
            style={StyleSheet.absoluteFill}
            device={device}
            isActive={true}
            frameProcessor={frameProcessor}
        />
    );

Tested with : "@shopify/react-native-skia": "2.2.13", "react-native-vision-camera": "4.7.2",

Behavior on Android:

  • Samsung s8: exception ERROR Frame Processor Error: Exception in HostFunction: Failed to convert NativeBuffer to SkImage!, js engine: VisionCamera
  • Android 14, works for a while then exception:

E Failed to acquire image. java.lang.IllegalStateException: maxImages (6) has already been acquired, call #close before acquiring more. at android.media.ImageReader.acquireNextImage(ImageReader.java:664) at androidx.camera.core.AndroidImageReaderProxy.acquireNextImage(AndroidImageReaderProxy.java:86) at androidx.camera.core.SafeCloseImageReaderProxy.acquireNextImage(SafeCloseImageReaderProxy.java:86) at androidx.camera.core.ImageAnalysisBlockingAnalyzer.acquireImage(ImageAnalysisBlockingAnalyzer.java:39) at androidx.camera.core.ImageAnalysisAbstractAnalyzer.onImageAvailable(ImageAnalysisAbstractAnalyzer.java:126) at androidx.camera.core.SafeCloseImageReaderProxy.lambda$setOnImageAvailableListener$1$androidx-camera-core-SafeCloseImageReaderProxy(SafeCloseImageReaderProxy.java:211) at androidx.camera.core.SafeCloseImageReaderProxy$$ExternalSyntheticLambda0.onImageAvailable(D8$$SyntheticClass:0) at androidx.camera.core.AndroidImageReaderProxy.lambda$setOnImageAvailableListener$0$androidx-camera-core-AndroidImageReaderProxy(AndroidImageReaderProxy.java:167) at androidx.camera.core.AndroidImageReaderProxy$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651) at java.lang.Thread.run(Thread.java:1119) 2025-09-10 11:26:40.472 11333-11579 ImageAnalysisAnalyzer

  • Android 15 and android 16: black screen.

maxximee avatar Sep 10 '25 02:09 maxximee

any update about black screen on android?

Atakaneliz avatar Sep 22 '25 14:09 Atakaneliz

any update about black screen on android?

Sadly android still not usable, I hope it will be fixed soon.

maxximee avatar Sep 23 '25 05:09 maxximee

Any news for the android fix?

Raman-Halder avatar Oct 08 '25 06:10 Raman-Halder

@wcandillon Hi William, Sorry to @ you directly, was wondering if there is a timeline when you would have time to look at the skiaFrameProcessor issue. I'm not sure it's related to the vision-camera or skia but it has been unusable since the start (trying since skia v1 all the way to latest version). Android crashes on about 10% of all devices and iOS has a memory leak leading to a crash on 100% of all devices. The only workaround for prod apps is to disable skia-frame-processor on android and set fps to 15 + image resolution to 2048x2048 on ios which gives pretty terrible results. Reproducing it is simple, I linked a git project above, basically empty project with just vison-camera and skia, add the skiaFrameProcessor and do nothing, just call frame.render()

maxximee avatar Dec 01 '25 04:12 maxximee

@maxximee It appears that texture.value?.dispose() in SkiaCameraCanvas.tsx is not properly disposing of the image, which is causing the memory leak. After I commented out snapshotCopy in useSkiaFrameProcessor.js, the crash no longer occurred.

ralph1233 avatar Dec 05 '25 11:12 ralph1233