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

makeImageSnapshot crashes Android app

Open Laityned opened this issue 1 year ago • 1 comments

Description

See Snack for reference code

When invoking makeImageSnapshot directly when a component loads, directly an snapshot is captured from the visible canvas using the useAnimatedReaction hook. However, the app crashes immediately. In sentry I can see that it is a segmentation fault.

When I am running makeImageSnapshot after trigger it by a separate button at a later moment, the app doesn't crash.

Version

1.3.9

Steps to reproduce

Run example with and without line 54 commented out.

Snack, code example, screenshot, or link to a repository

this snack was tested using a development build in a local repo instead, due to the dependencies

Laityned avatar Aug 01 '24 11:08 Laityned

I believe I'm encountering the same issue on iOS. It seems to me that the issue is with the API — there's no way to tell when the Skia view has finished rendering. If I do this:

const handleLayout = () => {
    const image = canvasRef.current?.makeImageSnapshot()
}

return (
    <Canvas
        ref={canvasRef}
        onLayout={handleLayout}
    />
)

It seems like there's a race condition — sometimes the snapshot is taken successfully, other times the app crashes with a "no Skia view available" error. It seems like all I can do is wrap the makeImageSnapshot in a timeout.

stevengoldberg avatar Oct 01 '24 22:10 stevengoldberg

This should be fixed in v1.6.0, if not please let me know.

wcandillon avatar Dec 03 '24 14:12 wcandillon