Skip to content
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

Merged
merged 2 commits into from
Aug 12, 2024
Merged

fix: thorvg canvas resize problem. #206

merged 2 commits into from
Aug 12, 2024

Conversation

hermet
Copy link
Member

@hermet hermet commented Jul 21, 2024

The canvas syncs before changing a target buffer.

thorvg/thorvg#2580

The canvas syncs before changing a target buffer.

thorvg/thorvg#2580
@hermet hermet added the bug Something isn't working label Jul 21, 2024
@hermet hermet requested a review from theashraf July 21, 2024 08:39
@hermet hermet self-assigned this Jul 21, 2024
Copy link

changeset-bot bot commented Jul 21, 2024

⚠️ No Changeset found

Latest commit: b60f668

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@theashraf
Copy link
Member

@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.mov

but thorvg 0.13.x still renders properly after calling resize:

Screen.Recording.2024-07-21.at.6.59.57.PM.mov

@hermet
Copy link
Member Author

hermet commented Jul 22, 2024

@theashraf Hi, It looks like the target size is not correctly set in width/height. May I ask you to check the return value Tvg_Result of both tvg_swcanvas_set_target() and tvg_canvas_sync() in the problematic resize()?

@theashraf
Copy link
Member

@hermet only tvg_canvas_sync returns TVG_RESULT_INSUFFICIENT_CONDITION (2), while tvg_swcanvas_set_target returns TVG_RESULT_SUCCESS (0).

@hermet
Copy link
Member Author

hermet commented Jul 24, 2024

@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?

@hermet
Copy link
Member Author

hermet commented Jul 24, 2024

@theashraf Just in case, could you please double-check that the buffer, width, and height values are properly updated when resize() is called? It's suspicious that it still holds the previous larger buffer and uses it in the web canvas.

@samuelOsborne
Copy link
Member

@theashraf I've updated to the most recent release of thorvg( v0.14.5) in this PR:

#216

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

@theashraf theashraf merged commit e10c5c0 into LottieFiles:main Aug 12, 2024
1 check passed
@hermet
Copy link
Member Author

hermet commented Aug 12, 2024

@samuelOsborne @theashraf fixed?

@theashraf
Copy link
Member

@samuelOsborne @theashraf fixed?

@hermet Yes, fixed with your changes + upgrading ThorVG to v0.14.5

@github-actions github-actions bot mentioned this pull request Aug 23, 2024
@theashraf
Copy link
Member

@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 ?

@hermet
Copy link
Member Author

hermet commented Aug 23, 2024

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

@tinyjin
Copy link
Member

tinyjin commented Aug 27, 2024

@theashraf Hello, I'm on checking this issue. Have just installed dotlottie-web and run web-example. Although I trigger resize, the issue doesn't appear.

How can I reproduce same situation you're encountering?

CleanShot.2024-08-27.at.17.23.58.mp4

@samuelOsborne
Copy link
Member

@tinyjin Please try resize the canvas by modifying its width / height in the inspector, then clicking resize

tinyjin added a commit that referenced this pull request Sep 3, 2024
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
tinyjin added a commit to tinyjin/dotlottie-rs that referenced this pull request Sep 4, 2024
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
theashraf pushed a commit that referenced this pull request Sep 4, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants