summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2022-04-30 23:19:20 +0200
committerkobewi <kobewi4e@gmail.com>2022-05-01 00:24:07 +0200
commitf473aab00d6dab7ebb746cdf8247c08d5515ec05 (patch)
treeb0411c1039a964164cb0cfccfd777fc6a76ba183 /scene
parentdb29d7753bb431f32058a2bf9f0e5b13fa99874f (diff)
Improve Tween infinite loop detection
Diffstat (limited to 'scene')
-rw-r--r--scene/animation/tween.cpp25
-rw-r--r--scene/animation/tween.h3
2 files changed, 18 insertions, 10 deletions
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index c6d59e7de4..24fbc1e431 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -278,14 +278,15 @@ bool Tween::step(float p_delta) {
bool step_active = false;
total_time += rem_delta;
+#ifdef DEBUG_ENABLED
+ float initial_delta = rem_delta;
+ bool potential_infinite = false;
+#endif
+
while (rem_delta > 0 && running) {
float step_delta = rem_delta;
step_active = false;
-#ifdef DEBUG_ENABLED
- float prev_delta = rem_delta;
-#endif
-
for (Ref<Tweener> &tweener : tweeners.write[current_step]) {
// Modified inside Tweener.step().
float temp_delta = rem_delta;
@@ -310,17 +311,21 @@ bool Tween::step(float p_delta) {
emit_signal(SNAME("loop_finished"), loops_done);
current_step = 0;
start_tweeners();
+#ifdef DEBUG_ENABLED
+ if (loops <= 0 && Math::is_equal_approx(rem_delta, initial_delta)) {
+ if (!potential_infinite) {
+ potential_infinite = true;
+ } else {
+ // Looped twice without using any time, this is 100% certain infinite loop.
+ ERR_FAIL_V_MSG(false, "Infinite loop detected. Check set_loops() description for more info.");
+ }
+ }
+#endif
}
} else {
start_tweeners();
}
}
-
-#ifdef DEBUG_ENABLED
- if (Math::is_equal_approx(rem_delta, prev_delta) && running && loops <= 0) {
- ERR_FAIL_V_MSG(false, "Infinite loop detected. Check set_loops() description for more info.");
- }
-#endif
}
return true;
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index 5c1567d510..40268405cf 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -116,6 +116,9 @@ private:
bool valid = false;
bool default_parallel = false;
bool parallel_enabled = false;
+#ifdef DEBUG_ENABLED
+ bool is_infinite = false;
+#endif
typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
static interpolater interpolaters[TRANS_MAX][EASE_MAX];