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

Some Tweeners are leaking references #52699

Closed
KoBeWi opened this issue Sep 15, 2021 · 3 comments · Fixed by #53135
Closed

Some Tweeners are leaking references #52699

KoBeWi opened this issue Sep 15, 2021 · 3 comments · Fixed by #53135

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Sep 15, 2021

Godot version

32f8f74

System information

W10

Issue description

Related to #51231

Tween and Tweeners had a circular reference, which prevented them from being freed properly (this was fixed by #51237)

However, Tween is still not being destroyed. Also if you use typed variable for tween, some Tweeners aren't destroyed too, which makes me think it's some GDScript bug. Here's test code:

extends Node2D
func _input(event):
	if event is InputEventKey and event.pressed:
		var tween = create_tween()
#		var tween: Tween = create_tween()
		tween.tween_property(self, "modulate", Color.RED, 1)
		tween.tween_interval(0.1)
		tween.tween_method(func(v): print(v), 0, 1, 0.1)
		tween.tween_callback(func(): print("finished"))

Run the scene, press any key and check the object Monitor. When animation starts, 5 objects are created and only 4 are destroyed when it ends; 1 object leaks (the Tween). When you switch to the commented line (so the tween is typed), 3 objects are leaked (Tween, IntervalTweener and CallbackTweener).

Steps to reproduce

See above.

Minimal reproduction project

You can compile engine with this patch for easier debugging:
0001-Add-Tween-destructor-prints.txt

@briansemrau
Copy link
Contributor

briansemrau commented Sep 27, 2021

@KoBeWi Are you checking for Tween destructor calls before or after the scene tree is destructed? After some investigation it seems that the SceneTree keeps a list of created tweens to supply SceneTree::get_processed_tweens. This keeps a reference to them and prevents them from being destructed.

Ref<Tween> SceneTree::create_tween() {

@briansemrau
Copy link
Contributor

Disregard my question above.

I've reproduced this issue.

extends Node2D

var tween1: Tween
var tween2: Tween

func _ready():
    tween1 = create_tween()
    tween2 = create_tween()
    tween1 = create_tween()
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: ObjectDB::cleanup (core\object\object.cpp:2022)
Leaked instance: Tween:-9222416011494424091
Leaked instance: Tween:-9222415461738610202
Leaked instance: Tween:-9222416561250237972

@Richard74Huang
Copy link

Richard74Huang commented Mar 17, 2022

Just a report,
I've noticed that create_tween and create_timer still cause leaking with in 4.0 build [41edfc8]

OS: macOS 12.3/arm64

Poobslag added a commit to Poobslag/turbofat that referenced this issue Sep 22, 2022
This reverts commit a1b1dbb.

Godot 3.5 introduced SceneTreeTweens, but these are still buggy and
result in reference leaks. When running Turbo Fat's puzzle mode, the
number of nodes gradually increases from 1,000 to 2,000, 3,000, and
keeps growing without limit. After a few minutes the game becomes choppy
and unplayable.

Removing the SceneTreeTweens fixes the problem. We can restore this code once
Godot #52699 is closed, and SceneTreeTweens work as intended.

See godotengine/godot#52699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants