luicfrr / react-native-vision-camera-face-detector

Vision Camera Frame Processor Plugin to detect faces using MLKit Face Detector
https://www.npmjs.com/package/react-native-vision-camera-face-detector
MIT License
124 stars 22 forks source link

[BUG] function '' cannot be shared error #38

Closed Sachin1116 closed 6 months ago

Sachin1116 commented 6 months ago

Frame Processor Error: Regular javascript function '' cannot be shared. Try decorating the function with the 'worklet' keyword to allow the javascript function to be used as a worklet., js engine: VisionCamera

Nurmehemmed commented 6 months ago

I am getting this error also

Sachin1116 commented 6 months ago

its working I change in babel

module.exports = { presets: ["module:@react-native/babel-preset"], plugins: [ ['react-native-reanimated/plugin', { processNestedWorklets: true }], ["react-native-worklets-core/plugin"] ] };

Nurmehemmed commented 6 months ago

My babel config is also same module.exports = { presets: ['module:@react-native/babel-preset'], plugins: [ ['react-native-worklets-core/plugin'], [ 'react-native-reanimated/plugin', { processNestedWorklets: true, }, ], ], }; can u share please your Camera component?

Sachin1116 commented 6 months ago

<Camera ref={camera} style={StyleSheet.absoluteFill} isActive={isCameraActive} device={cameraDevice} photo={true} // format={cameraFormat} onError={handleCameraMountError} faceDetectionCallback={handleFacesDetected} faceDetectionOptions={faceDetectionOptions} />

Nurmehemmed commented 6 months ago

how did you write handleFacesDetected component?

i wrote it like const handleFacesDetectionn = Worklets.createRunOnJS( (faces: Face[], frame: Frame) => {

Sachin1116 commented 6 months ago

https://github.com/nonam4/react-native-vision-camera-face-detector/blob/main/example/src/index.tsx

Nurmehemmed commented 6 months ago

i wrote same as @nonam4 example but it throw same error still :( Frame Processor Error: Regular javascript function '' cannot be shared. Try decorating the function with the 'worklet' keyword to allow the javascript function to be used as a worklet., js engine: VisionCamera

Nurmehemmed commented 6 months ago

i am using bare workflow

Sachin1116 commented 6 months ago

Getting error with Frame Processor Error: runOnJs(faces,frame).finally is not a function (it is undefined), js engine: VisionCamera

But when do changes in node modules react-native-vision-camera-face-detector camera.tsx its working fine.

const cameraFrameProcessor = useFrameProcessor( ( frame ) => { 'worklet' runAsync( frame, async () => { 'worklet' const internal = frame as FrameInternal const faces = detectFaces( frame )

  // increment frame count so we can use frame on 
  // js side without frame processor getting stuck
  internal.incrementRefCount()
  await runOnJs(
    faces,
    frame
  )
  // .finally( () => {
  //   // finally decrement frame count so it can be dropped
    internal.decrementRefCount()
  // } )
} )

}, [ runOnJs ] )

Nurmehemmed commented 6 months ago

@Sachin1116 thank you so much you saved me from getting fired))

luicfrr commented 6 months ago

I can't reproduce this issue. Everything is working fine for me in both example app and on my final project.

Nurmehemmed commented 6 months ago

There is some parameter that prevents this error for you. Maybe you have dedecting delay or something else? But This error happened for me 100% and fixed after apply @Sachin1116 last change

luicfrr commented 6 months ago

@Nurmehemmed Did you tested using example app?

Nurmehemmed commented 6 months ago

No i only test on my app but there is not something weird in my app. All dependencies versions are same with your example app. I tested on Samsung device when problem appear

luicfrr commented 6 months ago

Can you please check if f555c39 fix the issue?

luicfrr commented 6 months ago

I can confirm that original problem was solved on 1.6.1 version as it's working on builded (also store published) apps.