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: corrected thorvg canvas sync #222

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

tinyjin
Copy link
Member

@tinyjin tinyjin commented Aug 29, 2024

Ensure thorvg_canvas_sync is called in correct way, before buffer changes.


Essentially thorvg_canvas_sync() shouldn't interrupt following code lines, regardless of it's return value.

See the good example:
https://github.com/thorvg/thorvg/blob/main/src/bindings/wasm/tvgWasmLottieAnimation.cpp#L287

Corrected the function in fire-and-forget pattern.

Previously, lotte_renderer handle the InsufficientCondition(status == Status::Synced) as an error and block next steps in resize() function. (fell in that set_target, compute_layout never happend)

self.buffer
  .resize((self.width * self.height * 4) as usize, 0);
        
self.thorvg_canvas.sync()?;

// When canvas status is already `Synced`
// After this point, every lines blocked
self.thorvg_canvas
    .set_target(
        &mut self.buffer,
        self.width,
        self.width,
        self.height,
        get_color_space_for_target(),
    )
    .map_err(LottieRendererError::ThorvgError)?;

// ...

Ok(())

We shouldn't handle the status == Synced case as an error. Corrected the sync() without using the Rust try operator (?)


[Before]

CleanShot.2024-08-29.at.23.13.24.mp4

[After]

CleanShot.2024-08-29.at.23.08.37.mp4

Copy link

changeset-bot bot commented Aug 29, 2024

⚠️ No Changeset found

Latest commit: c4b917d

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

Copy link
Member

@hermet hermet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might need to double-check whether it works correctly if removing viewport call.

Copy link
Member

@theashraf theashraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @tinyjin, it works perfectly 🚀

@tinyjin tinyjin marked this pull request as draft August 30, 2024 02:27
@tinyjin
Copy link
Member Author

tinyjin commented Aug 30, 2024

Thanks @theashraf, ThorVG team also on reviewing some internal thing, changed to DRAFT. �I'll soon let u know when it's ready.

@tinyjin tinyjin self-assigned this Sep 3, 2024
@hermet hermet added the bug Something isn't working label Sep 3, 2024
@tinyjin tinyjin marked this pull request as ready for review September 3, 2024 10:39
@tinyjin
Copy link
Member Author

tinyjin commented Sep 3, 2024

@theashraf Updated logic more properly, please check again :)

Note that result of thorvg_canvas_sync() shouldn't be captured in animating logic.

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 theashraf merged commit 46ea758 into LottieFiles:main Sep 4, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Sep 4, 2024
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.

3 participants