Jelajahi Sumber

Improve Tween infinite loop detection

(cherry picked from commit f473aab00d6dab7ebb746cdf8247c08d5515ec05)
kobewi 3 tahun lalu
induk
melakukan
ce36f2f699
2 mengubah file dengan 18 tambahan dan 10 penghapusan
  1. 15 10
      scene/animation/scene_tree_tween.cpp
  2. 3 0
      scene/animation/scene_tree_tween.h

+ 15 - 10
scene/animation/scene_tree_tween.cpp

@@ -272,14 +272,15 @@ bool SceneTreeTween::step(float p_delta) {
 	bool step_active = false;
 	bool step_active = false;
 	total_time += rem_delta;
 	total_time += rem_delta;
 
 
+#ifdef DEBUG_ENABLED
+	float initial_delta = rem_delta;
+	bool potential_infinite = false;
+#endif
+
 	while (rem_delta > 0 && running) {
 	while (rem_delta > 0 && running) {
 		float step_delta = rem_delta;
 		float step_delta = rem_delta;
 		step_active = false;
 		step_active = false;
 
 
-#ifdef DEBUG_ENABLED
-		float prev_delta = rem_delta;
-#endif
-
 		List<Ref<Tweener>> &step = tweeners.write[current_step];
 		List<Ref<Tweener>> &step = tweeners.write[current_step];
 		for (int i = 0; i < step.size(); i++) {
 		for (int i = 0; i < step.size(); i++) {
 			Ref<Tweener> &tweener = step[i];
 			Ref<Tweener> &tweener = step[i];
@@ -307,17 +308,21 @@ bool SceneTreeTween::step(float p_delta) {
 					emit_signal(SceneStringNames::get_singleton()->loop_finished, loops_done);
 					emit_signal(SceneStringNames::get_singleton()->loop_finished, loops_done);
 					current_step = 0;
 					current_step = 0;
 					start_tweeners();
 					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 {
 			} else {
 				start_tweeners();
 				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;
 	return true;

+ 3 - 0
scene/animation/scene_tree_tween.h

@@ -88,6 +88,9 @@ private:
 	bool valid = false;
 	bool valid = false;
 	bool default_parallel = false;
 	bool default_parallel = false;
 	bool parallel_enabled = false;
 	bool parallel_enabled = false;
+#ifdef DEBUG_ENABLED
+	bool is_infinite = false;
+#endif
 
 
 	void start_tweeners();
 	void start_tweeners();