From 7dbea9c0b073787b5aad04c3bd8c37ef90326828 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 9 May 2020 21:38:28 +0300 Subject: [PATCH] Fixed stack overflow crash when the user set the loop mode to ping-pong and played the animation on a single frame with its own tag The crash only occured when it was one frame in that tag, but there were also more frames in general. A very rare scenario. --- src/Canvas.gd | 2 ++ src/UI/Timeline/AnimationTimeline.gd | 33 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Canvas.gd b/src/Canvas.gd index fef7a2e58..12cafeb9b 100644 --- a/src/Canvas.gd +++ b/src/Canvas.gd @@ -254,6 +254,8 @@ func _input(event : InputEvent) -> void: if Engine.get_version_info().major == 3 && Engine.get_version_info().minor >= 2: if event is InputEventMouseMotion: pen_pressure = event.pressure + + # To be removed once Godot 3.2.2 is out of beta if event.pressure == 0.0: # Drawing with mouse pen_pressure = 1 # This causes problems with tablets though diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index 732db9e21..98fd860df 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -225,6 +225,10 @@ func _on_PlayBackwards_toggled(button_pressed : bool) -> void: func _on_AnimationTimer_timeout() -> void: + if first_frame == last_frame: + $AnimationTimer.stop() + return + if animation_forward: if Global.current_frame < last_frame: Global.current_frame += 1 @@ -257,6 +261,21 @@ func _on_AnimationTimer_timeout() -> void: func play_animation(play : bool, forward_dir : bool) -> void: + first_frame = 0 + last_frame = Global.canvases.size() - 1 + if Global.play_only_tags: + for tag in Global.animation_tags: + if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]: + first_frame = tag[2] - 1 + last_frame = min(Global.canvases.size() - 1, tag[3] - 1) + + if first_frame == last_frame: + if forward_dir: + Global.play_forward.pressed = false + else: + Global.play_backwards.pressed = false + return + if forward_dir: Global.play_backwards.disconnect("toggled", self, "_on_PlayBackwards_toggled") Global.play_backwards.pressed = false @@ -267,20 +286,6 @@ func play_animation(play : bool, forward_dir : bool) -> void: Global.play_forward.pressed = false Global.change_button_texturerect(Global.play_forward.get_child(0), "play.png") Global.play_forward.connect("toggled", self, "_on_PlayForward_toggled") - if Global.canvases.size() == 1: - if forward_dir: - Global.play_forward.pressed = false - else: - Global.play_backwards.pressed = false - return - - first_frame = 0 - last_frame = Global.canvases.size() - 1 - if Global.play_only_tags: - for tag in Global.animation_tags: - if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]: - first_frame = tag[2] - 1 - last_frame = min(Global.canvases.size() - 1, tag[3] - 1) if play: Global.animation_timer.wait_time = 1 / fps