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 engine init and termination with reference counting of renderers #265

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

theashraf
Copy link
Member

@theashraf theashraf commented Nov 25, 2024

This update ensures that tvg_engine_init is called only once, provided no renderers are already created. It also ensures that tvg_engine_term is called when the last renderer is dropped, resolving an issue where creating a new renderer would unnecessarily reinitialize the engine and dropping it would attempt to terminate it again

@theashraf theashraf marked this pull request as ready for review November 25, 2024 17:42
@theashraf theashraf requested a review from dragostis November 25, 2024 17:43
Copy link

changeset-bot bot commented Nov 25, 2024

⚠️ No Changeset found

Latest commit: aeab801

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
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

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

I left just two comments because it seems to me like the approach won't work without some locking mechanism.

dotlottie-rs/src/lottie_renderer/thorvg.rs Outdated Show resolved Hide resolved
@theashraf theashraf force-pushed the fix/tvg_engine_term branch 2 times, most recently from af9d870 to faaf468 Compare November 28, 2024 16:59
@theashraf theashraf requested a review from dragostis November 28, 2024 16:59
@theashraf theashraf force-pushed the fix/tvg_engine_term branch from 04a9892 to 196e655 Compare December 6, 2024 11:14
@theashraf theashraf force-pushed the fix/tvg_engine_term branch 2 times, most recently from 2ec3604 to e7810ef Compare December 9, 2024 03:15
Copy link
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

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

LGTM with 2 comments that you might want to take a look at.

dotlottie-rs/src/lottie_renderer/thorvg.rs Outdated Show resolved Hide resolved
use std::thread;

#[test]
fn test_tvg_renderer_no_deadlock() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nit: this test might not actually capture a deadlock, so you can have false negatives here. It's still useful as a smoke test, but it might lead to a case like this:

  1. Alice make a PR with a concurrency bug, but the test happens to pass and is merged.
  2. Bob makes another PR that has nothing to do with concurrency, but his PR fails this regression test.

Up to you what you wanna do with it. :)

@theashraf theashraf merged commit ba1c5e1 into main Dec 12, 2024
1 check passed
@theashraf theashraf deleted the fix/tvg_engine_term branch December 12, 2024 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants