Fix T95395: dangling parent pointer when creating node group

Differential Revision: https://developer.blender.org/D13981
This commit is contained in:
Jacques Lucke 2022-02-01 17:48:44 +01:00
parent e9150ac317
commit 2bd71b49e7
Notes: blender-bot 2023-02-14 06:45:14 +01:00
Referenced by issue #95395, Crash making a node group with a frame
1 changed files with 12 additions and 0 deletions

View File

@ -776,6 +776,18 @@ static void node_group_make_insert_selected(const bContext &C, bNodeTree &ntree,
ListBase anim_basepaths = {nullptr, nullptr};
/* Detach unselected nodes inside frames when the frame is put into the group. Otherwise the
* `parent` pointer becomes dangling. */
LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
if (node->parent == nullptr) {
continue;
}
if (node_group_make_use_node(*node->parent, gnode) &&
!node_group_make_use_node(*node, gnode)) {
nodeDetachNode(node);
}
}
/* move nodes over */
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree.nodes) {
if (node_group_make_use_node(*node, gnode)) {