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
Fix crash on removing added sibling in _ready #78834
base: master
Are you sure you want to change the base?
Conversation
Could you provide a reproduction project? |
Better yet a formal bug report to track this in case this doesn't solve it |
Updated description with reproduction example |
Awaiting parent Also why is Edit: realized that won't necessarily catch this as it's not blocked at this point |
I though the purpose of the |
It's not safe, it's explicitly saying that you can't add children to parent if you try it:
You should do this in a separate function, or do the deferred call to keep this safe Does this happen if you call |
While we should prevent the crash, this example looks confusing. What's the real life need for this kind of logic?
I don't understand the intent here, and as mentioned As for the crash, we likely need to catch its condition with an |
@@ -1409,7 +1409,9 @@ void Node::add_sibling(Node *p_sibling, bool p_force_readable_name) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERR_FAIL_COND_MSG(data.blocked > 0
should more likely be
ERR_FAIL_COND_MSG(data.parent->data.blocked > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing out this fix right now, thank you
Of course doesn't fix this case specifically, but still relevant parallel issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also reorder checks a bit, two involving p_sibling
together and two involving data.parent
together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should add a data.blocked
around the actual child additions in _add_child_nocheck
, we do for removing and moving
Edit: a quick test with that works for this situation, but can't predict any issues from doing that, so would have to be investigated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name nocheck
suggests that it shouldn't do any checking :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mean checking, but data.blocked++
:P
I orignally came across this bug when making a building game. The logic was as follows:
My rationale for not throwing an error here was that replacing That being said, What do you think @YuriSizov @AThousandShips ? |
I think for now we can go with #78847 and then re-evaluate if there are still problems that cause crashes for your example. Then we can either update this PR to address them, or close it as superseded if #78847 ends up fixing all of it. |
As far as I understand #78834 (comment), the bug will not be completely fixed by #78847, which solves a related problem. As mentioned above, it should be investigated, if a |
I think the example I used in the description has caused some confusion, especially in my use of running the example in the extends Button
class MyNode extends Node:
func _ready() -> void:
get_parent().remove_child(self)
func _pressed() -> void:
add_sibling(MyNode.new())
The only way to address this with
|
If a Node that was added to the tree via
add_sibling()
was removed/reparented in its_ready()
function, it would cause a crash.Example: