Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated use of SceneTreeTween causes an endless loop #65891

Closed
colorworlds opened this issue Sep 16, 2022 · 3 comments · Fixed by #65896
Closed

Repeated use of SceneTreeTween causes an endless loop #65891

colorworlds opened this issue Sep 16, 2022 · 3 comments · Fixed by #65896

Comments

@colorworlds
Copy link

Godot version

v3.5.stable.official [991bb6a]

System information

win7,gles3

Issue description

Repeated use of SceneTreeTween causes an endless loop.

onready var _tween:SceneTreeTween = create_tween()

# Move to the specified location according to the specified time
func move_to(_new_pos:Vector2,_time:float):

	_tween.play()

	_tween.tween_property(self, "position", 
					  _new_pos , _time)

	yield(_tween,'finished')
	_tween.stop()

func _ready():
	yield(move_to(Vector2(100,100),1),'completed') # move to (100,100)

	yield(move_to(Vector2(200,100),1),'completed') # move to (100,100) ,(200,100)
	
	# yield(move_to(Vector2(200,200),1),'completed') # move to (100,100), ( 200,100),( 200,200) 

	# _tween.play() # This line of code will lead to an endless loop ,but  the same code exists in the move_to function

I'm going to change all the Tweet codes into new SceneTreeTween, but this problem makes me feel a risk.

I'm not sure if SceneTreeTween support reuse. But for example, when I want to achieve a screen shake effect, I need to ensure that the last screen shake effect is terminated first. In this way, I must keep the last SceneTreeTween every time, and then generate a new SceneTreeTween, which is counter intuitive.

Steps to reproduce

Transformer.zip

Minimal reproduction project

No response

@KoBeWi
Copy link
Member

KoBeWi commented Sep 16, 2022

I'm not sure if SceneTreeTween support reuse.

It kind of does, but not in an expected way. When you add a new Tweener, it gets added to what you already have. The animation is not reset between runs.

What happens in your example is:

  • you tween to 100, 100
  • you add another Tweener to the same SceneTreeTween (that have already finished)
  • the SceneTreeTween executes 100, 100 and then 200, 100
  • you then add yet another Tweener
  • so your final sequence is 100, 100 -> 200, 100 -> 200, 200
  • combined all these, you get: 100, 100 -> 100, 100 -> 200, 100 -> 100, 100 -> 200, 100 -> 200, 200
    godot windows tools x86_64_RQKeWdQRvN
    I'm a bit surprised that SceneTreeTween supports this kind of reuse, but it's an expected behavior in the end.

But for example, when I want to achieve a screen shake effect, I need to ensure that the last screen shake effect is terminated first. In this way, I must keep the last SceneTreeTween every time, and then generate a new SceneTreeTween, which is counter intuitive.

Yes, this is what you should do. You should also kill the previous SceneTreeTween if you are restarting animation. This was recently clarified here: #65658
tbh the SceneTreeTween documentation page is so detailed that I'd just suggest giving it a good read. The main clue is that SceneTreeTweens aren't supposed to be reused, because there is no point in doing that.

@KoBeWi KoBeWi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2022
@colorworlds
Copy link
Author

colorworlds commented Sep 16, 2022

@KoBeWi hello,The key problem is that the following line will cause the program to crash:

_tween.play()

An infinite loop indicates a program crash.
The complete code is like the following. I have asked others to test it on other computers. Crashes are bound to happen:

func _ready():
	yield(move_to(Vector2(100,100),1),'completed') # move to (100,100)

	yield(move_to(Vector2(200,100),1),'completed') # move to (100,100) ,(200,100)

	_tween.play() 

@KoBeWi
Copy link
Member

KoBeWi commented Sep 16, 2022

Ah I missed it, because it was commented out in your MRP.
Crash stack trace:

CrashHandlerException: Program crashed
Engine version: Godot Engine v4.0.beta.custom_build (d1b2a191ab752ebd8236e3547e07b6eb3bb1f260)
Dumping the backtrace. Please include this when reporting the bug on: https://github.com/godotengine/godot/issues
[0] VectorWriteProxy<List<Ref<Tweener>,DefaultAllocator> >::operator[] (C:\Users\Tomek\Desktop\Godot\godot\core\templates\vector.h:52)
[1] Tween::step (C:\Users\Tomek\Desktop\Godot\godot\scene\animation\tween.cpp:298)
[2] SceneTree::process_tweens (C:\Users\Tomek\Desktop\Godot\godot\scene\main\scene_tree.cpp:560)
[3] SceneTree::process (C:\Users\Tomek\Desktop\Godot\godot\scene\main\scene_tree.cpp:479)
[4] Main::iteration (C:\Users\Tomek\Desktop\Godot\godot\main\main.cpp:3005)
[5] OS_Windows::run (C:\Users\Tomek\Desktop\Godot\godot\platform\windows\os_windows.cpp:895)
[6] widechar_main (C:\Users\Tomek\Desktop\Godot\godot\platform\windows\godot_windows.cpp:179)
[7] _main (C:\Users\Tomek\Desktop\Godot\godot\platform\windows\godot_windows.cpp:201)
[8] main (C:\Users\Tomek\Desktop\Godot\godot\platform\windows\godot_windows.cpp:215)
[9] WinMain (C:\Users\Tomek\Desktop\Godot\godot\platform\windows\godot_windows.cpp:229)
[10] __scrt_common_main_seh (d:\a01\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[11] BaseThreadInitThunk
-- END OF BACKTRACE --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants