-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: thorvg canvas resize problem. #206
Conversation
The canvas syncs before changing a target buffer. thorvg/thorvg#2580
|
@hermet the resize issue is not fixed yet. please check this recording for thorvg 0.14.x. calling resize causes a rendering issue: Screen.Recording.2024-07-21.at.6.54.32.PM.movbut thorvg 0.13.x still renders properly after calling resize: Screen.Recording.2024-07-21.at.6.59.57.PM.mov |
@theashraf Hi, It looks like the target size is not correctly set in width/height. May I ask you to check the return value |
@hermet only tvg_canvas_sync returns TVG_RESULT_INSUFFICIENT_CONDITION (2), while tvg_swcanvas_set_target returns TVG_RESULT_SUCCESS (0). |
@theashraf Hmm. tvg_swcanvas_set_target() seems working then. Upon examining the video, it appears that the actual buffer size is larger than the width and height specified by ThorVG. If the reverse were true, it would cause crashes rather than displaying a broken image. It's possible that dotLottie is passing the wrong width and height, which differs from the actual target buffer. Is this a possibility? One more question: It also resized smaller properly when the panel size is narrowed. How's different when the resize button is clicked? |
@theashraf Just in case, could you please double-check that the buffer, width, and height values are properly updated when |
@theashraf I've updated to the most recent release of thorvg( v0.14.5) in this PR: As well as added @hermet's changes and can't reproduce the bug, could you please check on your end ? You can find the artifacts for that branch already built here: https://github.com/LottieFiles/dotlottie-rs/actions/runs/10332417019 |
@samuelOsborne @theashraf fixed? |
@hermet Yes, fixed with your changes + upgrading ThorVG to v0.14.5 |
@hermet The issue with dotlottie-rs still persists, even after applying the suggested fix. I've verified that the frame buffer is being resized correctly and matches the canvas width and height. Below is the relevant code on web. The resize function appears to be working as expected, and the frame buffer size is updated accordingly based on the new canvas dimensions. function resize() {
const { width: clientWidth, height: clientHeight } = canvas.getBoundingClientRect();
const width = Math.floor(clientWidth * (window.devicePixelRatio || 1));
const height = Math.floor(clientHeight * (window.devicePixelRatio || 1));
canvas.width = width;
canvas.height = height;
dotLottiePlayer.resize(width, height);
}
function render() {
const rendered = dotLottiePlayer.render();
if (rendered) {
const actualFrameBuffer = dotLottiePlayer.buffer();
const expectedFrameBufferSize = canvas.width * canvas.height * 4;
if (actualFrameBuffer.length !== expectedFrameBufferSize) {
// never fails 🤔
throw new Error("Frame buffer size mismatch");
}
const imageData = ctx.createImageData(canvas.width, canvas.height);
imageData.data.set(actualFrameBuffer);
ctx.putImageData(imageData, 0, 0);
}
} Despite the frame buffer resizing as expected, the problem persists. Could you provide any further insights into what might be causing this ? |
I think it needs a user-side update, as thorvg.viewer has no regressions so far. Could you please review the dotlottie? @tinyjin 2024-08-23-14-14-10.mp4 |
@theashraf Hello, I'm on checking this issue. Have just installed dotlottie-web and run web-example. Although I trigger How can I reproduce same situation you're encountering? CleanShot.2024-08-27.at.17.23.58.mp4 |
@tinyjin Please try resize the canvas by modifying its width / height in the inspector, then clicking resize |
Ensure `thorvg_canvas_sync` is called before buffer changes. Additionally, the function should not disrupt subsequent code execution, regardless of its return value. Call the function without using the Rust try operator (`?`). Issue: #206
Ensure `thorvg_canvas_sync` is called before buffer changes. Additionally, the function should not disrupt subsequent code execution, regardless of its return value. Call the function without using the Rust try operator (`?`). Issue: LottieFiles#206
Ensure `thorvg_canvas_sync` is called before buffer changes. Additionally, the function should not disrupt subsequent code execution, regardless of its return value. Call the function without using the Rust try operator (`?`). Issue: #206
The canvas syncs before changing a target buffer.
thorvg/thorvg#2580