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

Reference to freed node equates to true in conditional #82656

Closed
Wabafet opened this issue Oct 2, 2023 · 3 comments
Closed

Reference to freed node equates to true in conditional #82656

Wabafet opened this issue Oct 2, 2023 · 3 comments

Comments

@Wabafet
Copy link

Wabafet commented Oct 2, 2023

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Godot v4.1.1.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 (NVIDIA; 31.0.15.3623) - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

Issue description

I have a reference to a node that is then deleted with queue_free() which causes the reference to be set to null. The debugger tells me this reference is now however it still passes an if condition as if it were not null. Directly comparing it to null has the expected result (ie. freed_reference == null -> true) however just testing the reference itself does not (ie. if freed_reference: -> passes).

Steps to reproduce

Add a node to the scene and attach the following script.

extends Node

var freed_node: Node = null

func _ready():
	freed_node = Node.new()

func _process(delta):
	if freed_node != null:
		freed_node.queue_free() #Breakpoint here will be hit one time only, as expected
		return
	if freed_node:
		pass #Breakpoint here should never be hit but is

Minimal reproduction project

N/A

@Calinou
Copy link
Member

Calinou commented Oct 2, 2023

This is done for performance reasons. Use is_instance_valid(freed_node) to check for validity instead of a direct null check.

@dalexeev
Copy link
Member

dalexeev commented Oct 2, 2023

@Calinou
Copy link
Member

Calinou commented Oct 2, 2023

Thanks for the report! Consolidating in #59816.

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