Shopify / Shopify/react-native-skia

How to use frameProcessor with useSkiaFrameProcessor ? my app crashes when running

Open
#3,602 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
8.6k
Forks
647
Avg merge
1d 17h
Merged PRs (30d)
35

Description

Description

Dear all, i just tested with a simple code of tsx:

`import { PaintStyle, Skia } from '@shopify/react-native-skia';
import React from 'react';
import { StyleSheet } from 'react-native';
import {
Camera,
useCameraDevice,
useSkiaFrameProcessor,
} from 'react-native-vision-camera';

const paint = Skia.Paint();

paint.setColor(Skia.Color('red'));
paint.setStyle(PaintStyle.Stroke); // or 'fill'
paint.setStrokeWidth(8);

export default function SkiaCamera(): React.ReactNode {
const device = useCameraDevice('back');

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

// 1. Render camera frame
frame.render();

// 2. Center rect size
const rectWidth = frame.width / 3;
const rectHeight = frame.height / 4;

const left = (frame.width - rectWidth) / 2;
const top = (frame.height - rectHeight) / 2;

// 3. Create Skia rect
const rect = Skia.XYWHRect(left, top, rectWidth, rectHeight);

// 4. Draw on the frame
frame.drawRect(rect, paint);

}, []);

if (!device) return null;

return (

);
};

const styles = StyleSheet.create({
camera: { flex: 1 },
});`

but when tested on device, the app crashed and exit.
when testing with XCode, i have these debug info:

anyone can help about using worklet and frame to draw some rect with useSkiaFrameProcessor ? thanks a lot

terminating due to uncaught exception of type facebook::jsi::JSError: Cannot read property 'width' of undefined
TypeError: Cannot read property 'width' of undefined
at shopify_CanvasTsx1 (/Users/nan/Desktop/RNProjects/fashioncapv1/node_modules/@shopify/react-native-skia/src/renderer/Canvas.tsx:119:26)
at anonymous (/Users/nan/Desktop/RNProjects/fashioncapv1/node_modules/react-native-reanimated/src/frameCallback/FrameCallbackRegistryUI.ts:58:38)
at forEach (native)
at loop (/Users/nan/Desktop/RNProjects/fashioncapv1/node_modules/react-native-reanimated/src/frameCallback/FrameCallbackRegistryUI.ts:49:43)
at anonymous (/Users/nan/Desktop/RNProjects/fashioncapv1/node_modules/react-native-worklets/src/runLoop/uiRuntime/requestAnimationFrame.ts:28:16)
at anonymous (/Users/nan/Desktop/RNProjects/fashioncapv1/node_modules/react-native-worklets/src/runLoop/uiRuntime/requestAnimationFrame.ts:48:42)
at callGuard (native)

React Native Skia Version

2.4.7

React Native Version

0.81.5

Using New Architecture
  • Enabled
Steps to Reproduce

copy my code an tsx file and test with xcode build of iOS.

`import { PaintStyle, Skia } from '@shopify/react-native-skia';
import React from 'react';
import { StyleSheet } from 'react-native';
import {
Camera,
useCameraDevice,
useSkiaFrameProcessor,
} from 'react-native-vision-camera';

const paint = Skia.Paint();

paint.setColor(Skia.Color('red'));
paint.setStyle(PaintStyle.Stroke); // or 'fill'
paint.setStrokeWidth(8);

export default function SkiaCamera(): React.ReactNode {
const device = useCameraDevice('back');

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

// 1. Render camera frame
frame.render();

// 2. Center rect size
const rectWidth = frame.width / 3;
const rectHeight = frame.height / 4;

const left = (frame.width - rectWidth) / 2;
const top = (frame.height - rectHeight) / 2;

// 3. Create Skia rect
const rect = Skia.XYWHRect(left, top, rectWidth, rectHeight);

// 4. Draw on the frame
frame.drawRect(rect, paint);

}, []);

if (!device) return null;

return (

);
};

const styles = StyleSheet.create({
camera: { flex: 1 },
});
`

Snack, Code Example, Screenshot, or Link to Repository

import { PaintStyle, Skia } from '@shopify/react-native-skia';
import React from 'react';
import { StyleSheet } from 'react-native';
import {
Camera,
useCameraDevice,
useSkiaFrameProcessor,
} from 'react-native-vision-camera';

const paint = Skia.Paint();

paint.setColor(Skia.Color('red'));
paint.setStyle(PaintStyle.Stroke); // or 'fill'
paint.setStrokeWidth(8);

export default function SkiaCamera(): React.ReactNode {
const device = useCameraDevice('back');

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

// 1. Render camera frame
frame.render();

// 2. Center rect size
const rectWidth = frame.width / 3;
const rectHeight = frame.height / 4;

const left = (frame.width - rectWidth) / 2;
const top = (frame.height - rectHeight) / 2;

// 3. Create Skia rect
const rect = Skia.XYWHRect(left, top, rectWidth, rectHeight);

// 4. Draw on the frame
frame.drawRect(rect, paint);

}, []);

if (!device) return null;

return (

);
};

const styles = StyleSheet.create({
camera: { flex: 1 },
});

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced TSX example and the stack trace into @shopify/react-native-skia/src/renderer/Canvas.tsx:119, then inspect the React Native Worklets and Reanimated frame-callback entries shown there. Use an iOS/Xcode build to determine why the frame is undefined during useSkiaFrameProcessor execution; done means the crash cause and a verified working usage path are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
computer-graphics, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.