Merge pull request #90992 from RadiantUwU/fix_node_duplicate

Fix `Node.duplicate()` crash when duplicating a node that cannot be instantiated.
This commit is contained in:
Rémi Verschelde 2024-08-19 14:33:31 +02:00
commit 6d22b8026d
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 5 additions and 1 deletions

View File

@ -2809,9 +2809,11 @@ Node *Node::duplicate(int p_flags) const {
ERR_THREAD_GUARD_V(nullptr);
Node *dupe = _duplicate(p_flags);
ERR_FAIL_NULL_V_MSG(dupe, nullptr, "Failed to duplicate node.");
_duplicate_properties(this, this, dupe, p_flags);
if (dupe && (p_flags & DUPLICATE_SIGNALS)) {
if (p_flags & DUPLICATE_SIGNALS) {
_duplicate_signals(this, dupe);
}
@ -2827,6 +2829,8 @@ Node *Node::duplicate_from_editor(HashMap<const Node *, Node *> &r_duplimap, con
int flags = DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANTIATION | DUPLICATE_FROM_EDITOR;
Node *dupe = _duplicate(flags, &r_duplimap);
ERR_FAIL_NULL_V_MSG(dupe, nullptr, "Failed to duplicate node.");
_duplicate_properties(this, this, dupe, flags);
// This is used by SceneTreeDock's paste functionality. When pasting to foreign scene, resources are duplicated.