From 5c1195e456a168486c251340275ad8e9193873e9 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 17 Sep 2021 00:50:07 +0200 Subject: [PATCH] Add a special case for 0-time interpolations --- doc/classes/Tween.xml | 1 + thirdparty/misc/easing_equations.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml index ede6e2fdd53..f94018c96bb 100644 --- a/doc/classes/Tween.xml +++ b/doc/classes/Tween.xml @@ -86,6 +86,7 @@ [code]initial_value[/code] is the starting value of the interpolation. [code]delta_value[/code] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code]. [code]duration[/code] is the total time of the interpolation. + [b]Note:[/b] If [code]duration[/code] is equal to [code]0[/code], the method will always return the final value, regardless of [code]elapsed_time[/code] provided. diff --git a/thirdparty/misc/easing_equations.cpp b/thirdparty/misc/easing_equations.cpp index ce32c1a3625..d164e3d5600 100644 --- a/thirdparty/misc/easing_equations.cpp +++ b/thirdparty/misc/easing_equations.cpp @@ -312,6 +312,10 @@ Tween::interpolater Tween::interpolaters[Tween::TRANS_MAX][Tween::EASE_MAX] = { }; real_t Tween::run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) { + if (d == 0) { + // Special case to avoid dividing by 0 in equations. + return b + c; + } interpolater cb = interpolaters[p_trans_type][p_ease_type]; ERR_FAIL_COND_V(cb == NULL, b);