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

Variants pointer to object can unadvertedly become invalid #35488

Closed
RandomShaper opened this issue Jan 23, 2020 · 1 comment
Closed

Variants pointer to object can unadvertedly become invalid #35488

RandomShaper opened this issue Jan 23, 2020 · 1 comment

Comments

@RandomShaper
Copy link
Member

Godot version:
All of them? (At least 3.1.x and 3.2.x.)

OS/device including version:
N/A

Issue description:

The problem is the way Godot manages the memory of non-Resource objects. Since they are not reference-counted, you can have Variants with dangling pointers to freed ones. This is a big problem, because it affects scripting.

In addition, if a newly created object happens to be at the same address of a freed one, any dangling pointer to the old one will be effectively pointing to the new one.

Steps to reproduce:

This simple code is able to demonstrate the problem:

func _ready():
	var a = []
	var c = MarginContainer.new()
	a.append(c)
	print(a[0])
	c.free()
	print(a[0])
	TextureRect.new()
	print(a[0])

Output:

[MarginContainer:1171]
[Deleted Object]
[TextureRect:1172]

As can be seen, the TextureRect has been allocated at the same address the MarginContainer was.

Minimal reproduction project:

Not needed.

@RandomShaper
Copy link
Member Author

Duplicate of #32383.

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

No branches or pull requests

3 participants