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

Add a special case for 0-time interpolations #53003

Merged
merged 1 commit into from
Sep 24, 2021

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Sep 24, 2021

Most of interpolation equations divide by duration, which results in infinite final value if it's 0. I added a special case for 0 duration, so now it ends instantly without computing anything.

Fixes #40843

Could be probably cherry-picked, because the interpolation method is the same (except it's not exposed).

@KoBeWi KoBeWi added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:animation labels Sep 24, 2021
@KoBeWi KoBeWi added this to the 4.0 milestone Sep 24, 2021
@KoBeWi KoBeWi requested review from a team as code owners September 24, 2021 10:37
@@ -318,6 +318,11 @@ bool Tween::should_pause() {
}

Variant Tween::interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, TransitionType p_trans, EaseType p_ease) {
if (p_duration == 0) {
// Special case to avoid dividing by 0 in equations.
return p_initial_val + p_delta_val;
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't work sadly:

 scene/animation/tween.cpp:323:24: error: use of overloaded operator '+' is ambiguous (with operand types 'Variant' and 'Variant')
                return p_initial_val + p_delta_val;
                       ~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, this should've gone into easing equations .-.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I guess this is why I originally wanted to PR it after merging #50165 🤔

@akien-mga akien-mga merged commit 5e4a712 into godotengine:master Sep 24, 2021
@akien-mga
Copy link
Member

Thanks!

@KoBeWi KoBeWi deleted the tween_0() branch September 24, 2021 11:28
@akien-mga
Copy link
Member

Cherry-picked for 3.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node disappears when animating a Tween with duration of 0
2 participants