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

[Bug] spurious orphans when doubling #435

Closed
feefladder opened this issue Oct 6, 2022 · 2 comments
Closed

[Bug] spurious orphans when doubling #435

feefladder opened this issue Oct 6, 2022 · 2 comments

Comments

@feefladder
Copy link

So, when having a class like this:

extends Node
class_name IMakeOrphans

var node = Node.new()

func _ready():
#     node = Node.new()
    add_child(node)

and double it, I get orphan messages:

extends GutTest

func test_no_orphans():
    add_child_autofree(IMakeOrphans.new())
    pass_test("should have no orphans")

func test_orphans():
    add_child_autoqfree(double(IMakeOrphans).new())
    pass_test("should have an orphan")

func test_orphans_partial():
    add_child_autoqfree(partial_double(IMakeOrphans).new())
    pass_test("should also have an orphan")

makes 2 orphans.

However, if the class would be like this:

extends Node
class_name IMakeOrphans

var node: Node

func _ready():
    node = Node.new()
    add_child(node)

no orhpans are created.

Not sure what causes it, but I think the script is run once when doubling?

@feefladder feefladder changed the title spurious orphans when doubling [Edit] spurious orphans when doubling Oct 6, 2022
@feefladder feefladder changed the title [Edit] spurious orphans when doubling [Bug] spurious orphans when doubling Oct 6, 2022
@bitwes
Copy link
Owner

bitwes commented Oct 7, 2022

The script is run once. You can add:

func _notification(what):
	if(what == NOTIFICATION_PREDELETE):
		<free things here if they exist>

so that any nodes you have created are deleted when not in the tree.

@bitwes
Copy link
Owner

bitwes commented Feb 23, 2023

Reopen if the last comment did not address the issue.

@bitwes bitwes closed this as completed Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants