浏览代码

Fix AnimatedSprite infinite loop

Haoyu Qiu 3 年之前
父节点
当前提交
3a439a9c03
共有 2 个文件被更改,包括 10 次插入10 次删除
  1. 5 5
      scene/2d/animated_sprite_2d.cpp
  2. 5 5
      scene/3d/sprite_3d.cpp

+ 5 - 5
scene/2d/animated_sprite_2d.cpp

@@ -158,14 +158,14 @@ void AnimatedSprite2D::_notification(int p_what) {
 				return;
 			}
 
-			double speed = frames->get_animation_speed(animation) * speed_scale;
-			if (speed == 0) {
-				return; //do nothing
-			}
-
 			double remaining = get_process_delta_time();
 
 			while (remaining) {
+				double speed = frames->get_animation_speed(animation) * speed_scale;
+				if (speed == 0) {
+					return; // Do nothing.
+				}
+
 				if (timeout <= 0) {
 					timeout = _get_frame_duration();
 

+ 5 - 5
scene/3d/sprite_3d.cpp

@@ -1019,14 +1019,14 @@ void AnimatedSprite3D::_notification(int p_what) {
 				return;
 			}
 
-			float speed = frames->get_animation_speed(animation);
-			if (speed == 0) {
-				return; //do nothing
-			}
-
 			double remaining = get_process_delta_time();
 
 			while (remaining) {
+				double speed = frames->get_animation_speed(animation);
+				if (speed == 0) {
+					return; // Do nothing.
+				}
+
 				if (timeout <= 0) {
 					timeout = 1.0 / speed;