From 5c0f7968e35622a1b9fe8dac78e57609b04147b7 Mon Sep 17 00:00:00 2001 From: kobewi Date: Tue, 7 May 2024 21:43:13 +0200 Subject: [PATCH] Fix crash when adding a child while duplicating a node --- scene/main/node.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 827273132c7..e54209c1dd4 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2930,8 +2930,10 @@ void Node::_duplicate_properties_node(const Node *p_root, const Node *p_original } } - for (int i = 0; i < p_copy->get_child_count(); i++) { - _duplicate_properties_node(p_root, p_original->get_child(i), p_copy->get_child(i)); + for (int i = 0; i < p_original->get_child_count(); i++) { + Node *copy_child = p_copy->get_child(i); + ERR_FAIL_NULL_MSG(copy_child, "Child node disappeared while duplicating."); + _duplicate_properties_node(p_root, p_original->get_child(i), copy_child); } }