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

tvg_set_frame fails on lastframe #2147

Closed
theashraf opened this issue Apr 5, 2024 · 3 comments
Closed

tvg_set_frame fails on lastframe #2147

theashraf opened this issue Apr 5, 2024 · 3 comments
Assignees
Labels
bug Something isn't working lottie Lottie animation
Milestone

Comments

@theashraf
Copy link
Member

in dotLottie-rs, I'm facing an issue with a lottie animation consists of 42 total frames, and when tvg_set_frame is called in the animation loop with last_frame set to 41, it sometimes returns TVG_RESULT_INSUFFICIENT_CONDITION. This error prevents the animation from reaching its completion condition. Interestingly, this issue only occurs if the penultimate frame (pre_last_frame) is interpolated to a value very close to the last frame (for example, 40.99977). When frame interpolation is disabled, this issue does not occur.

Here is the asset link for reference: R3nSQxmVaC.json

Below is the Rust test code snippet illustrating the problem:

#[test]
fn test_set_frame_fail_for_last_frame() {
    let player = DotLottiePlayer::new(Config::default());

    assert!(
        player.load_animation_path("tests/assets/test.json", WIDTH, HEIGHT),
        "Animation should load."
    );

    let total_frames = 42.0;

    assert!(player.set_frame(total_frames - 1.0 - 0.0005), "Setting frame should pass.");
    assert_eq!(player.current_frame(), total_frames - 1.0 - 0.0005, "Current frame should match.");

    // For some reason, set_frame here fails in ThorVG with a result of 2, which corresponds to TVG_RESULT_INSUFFICIENT_CONDITION
    assert!(player.set_frame(total_frames - 1.0), "Setting the last frame should pass."); // This line fails
}

Any insights into why this might be happening?

@hermet hermet added the lottie Lottie animation label Apr 5, 2024
@hermet
Copy link
Member

hermet commented Apr 5, 2024

It looks like a floating-point precision problem.

@hermet
Copy link
Member

hermet commented Apr 9, 2024

@theashraf Hello, this is a good topic to discussion. Currently, tvg ignores the frame value if the difference is less than 0.001. How could people notice changes within 1ms? In most cases, in my opinion, updating the frames when the change is less than 1ms is just an unnecessary burden on the system.

In your case, the difference is approximately 0.00023, tvg returns the false to skip the frame update by user as it's intended to use like this:

if (animation->frame( new frame value) == success) {
   //Good to update the frame.
} else {
   //Not necessarily, skip the update.
}

Thus, I suggest a more practical test:

(total_frames - 1.0 - 0.001)

or

assert(animation->frame(new frame value) != Resut::NonSupport)

Please feel free to leave your opinion if you have different thought. Thanks.

hermet added a commit that referenced this issue Apr 9, 2024
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: #2147
hermet added a commit that referenced this issue Apr 9, 2024
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: #2147
@theashraf
Copy link
Member Author

Thank you, @hermet. That makes sense

hermet added a commit that referenced this issue Apr 11, 2024
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: #2147
hermet added a commit that referenced this issue Apr 19, 2024
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: #2147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lottie Lottie animation
Projects
Status: Done 0.14
Development

No branches or pull requests

2 participants