Skip to content

Adding and removing child nodes in update callback #1256

Closed Answered by robertosfield
keince asked this question in Q&A
Discussion options

You must be logged in to vote

If you add and removing children during traversals, including the update traversal, you have to be very careful about avoiding invalidation of the iterators that are being used during traversal.

It is generally safe to add/remove children that are below the node that has the callback , but going back to the node parent's or any node in the parent chain you will invalidate iterators, so those iterators will likely cause a crash as they'll be pointing to now deleted or repurposed memory.

Personally I'd recommend doing add/removing at the top level rather than inside the scene graph.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@keince
Comment options

@robertosfield
Comment options

@keince
Comment options

Answer selected by robertosfield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants