New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buggy .makeImageSnapshot() on IOS #1811
Comments
I'm having the same issue. I checked the file and it is always empty |
I'm struggling to understand the issue based on the video, could you walk me thought it? |
Same issue but I believe it only happens in dev builds. Does the issue happen in a production build for you @sravis02? What happens for me: I have a canvas with various elements. When I call makeImageSnapshot in the local dev builds, the resulting image sometimes doesn't contain all my elements from the canvas. It quickly blinks (like in your screen recording) and it seems as the elements are scaled down and on the top left corner falsely positioned. In production I cannot reproduce this so far... |
thats exactly the issue i am having. it occurs on expo development builds, expo prebuild builds and expo internal preview builds for me. |
i will take a look into it again and try to provide some minimal reproduceable tests |
This is very similar to the issues @ludwighen had |
Probably related to #2133 |
Following up on this, I think I found a workaround for the issue @cesargdm. Indeed I have the same issue and I first thought it would only happen in my development builds but it also happened in production, only for less powerful devices. It was probably visible in the development builds because they are a bit less performant, and something obviously tries to render the moment the snapshot is taken. I assume in most attempts it's fast enough to take the image after this drawing process. I figured what if I just delay the makeImageScreenshot by one render cycle using setTimeout. And it works. I have no idea why 😅, but with over 100 attempts, I now can no longer reproduce the issue, so I believe it fixed it. Let me know if it works for you too. Here's my code:
|
thanks a lot, this workaround works for me :) @ludwighen |
Update: Unfortunately the hack doesn't work fully reliable after all.. Feels to me like some sort of race condition where the snapshot happens just before the drawing on the canvas is finished? |
this bug looks interesting and I will investigate it further but in the meantime, I recommend to draw the content offscreen and take a snapshot of that: https://shopify.github.io/react-native-skia/docs/animations/textures#usetexture |
Thanks @wcandillon, indeed that's what I planned to do next... I'll keep you posted |
Gang, I think that this PR may fix the issue: #2254, any chance you could try this patch on your app? |
nice! |
that's a fair question, I was asking just in case, we will publish
this bug fix soon so you will be able to test on the publish version.
But now I am realizing that these a not related most likely.
I will try to investigate this particular issue still
…On Mon, Feb 26, 2024 at 10:18 PM ludwighen ***@***.***> wrote:
nice!
Probably dumb question but do I need to build skia locally to do that?
If I install from your branch it get's added as react-native-skia-dev-tools.
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
So I tested your fix with 0.1.241 beta but the issue is still there. Next I tried the useTexture approach but I cannot get the basic example working.
Any idea why? While looking into all of this, I was wondering if my current approach is even the "right" way, I think I should switch to the imperative API. I know it's not the right thread for it, but given that it would likely mean a significant refactor for me, maybe you could point in me the right direction since the documentation is a bit limited for the imperative API 🥲. Basically, I have a canvas that can contain lots of different elements from the user (images, svgs, paths, etc.), think something like the Instagram stories editor / stickers example.
And then essentially the CanvasElement conditionally renders Skia images, svgs, paths, etc. and applies transforms from GestureHandlers. The useTexture hook would not allow me to pass the same logic in, would it? Anyways, thanks a ton @wcandillon as always 🙏 |
Update: I finally was able to solve it (this time reliably @sravis02 @cesargdm). Not using the canvas ref's makeImageSnapshot() but instead drawing offscreen indeed fixes the problem and it also revealed why the items glitched small in the top left corner. It has something to do with the scale/pixel density. What I did is just putting the Canvas children 1 to 1 but it has the caveat that the sizing is not identical to the onscreen canvas:
So basically, when I use the normal canvasWidth/canvasHeight (via height/width from useWindowDimensions), the offscreen canvas is very small because it uses them as absolute pixel values whereas with the declarative API the pixels are scaled according to device (i.e. 3x for iPhones). So the little glitch we see when using the ref's makeImageSnapshot method is basically the non-upscaled dimensions. Does this somehow help you in debugging @wcandillon ? Hope that helps |
Thank you for this. But I will definitely revisit. For |
Description
When I want to snapshot my Skia canvas (which is not that small), it gets buggy.
These bugs don't occur always. If you try it multiple times, you will see that sometimes it works fine.
Screenrecording of the bug:
https://www.youtube.com/shorts/mH7VuiT7CuU
What bugs?:
Does RNSkia somehow rerender the Canvas, when the method makeImageSnapshot gets executed?
If yes, I think, the snapshot is taken before the rerender process is completely finished.
It makes no sense to me, since the only code that gets triggered on the button click is this one:
Version
0.1.197 in repro but also appears in 0.1.202
Steps to reproduce
How to reproduce:
npm install
On Mac simulator
npx expo run:ios
On Iphone with EAS
eas build --profile development --platform ios
npx expo start --dev-client
In the App
Snack, code example, screenshot, or link to a repository
I couldn't really reproduce this in any test projects sadly.
This only happened in my big project, i guess its because it has more heavy operations.
https://github.com/sravis02/flashes-app
Branch: issue-react-native-skia
I invited you both (chrfalch & wcandillion) to my repository
The Canvas is in PreviewCanvas.tsx
The Snapshotfunction in preview.tsx
The text was updated successfully, but these errors were encountered: