diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-04-03 13:10:29 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-04-03 13:10:29 +0400 |
commit | bb4ab6a007ddc1130cc80439c9d4cd89c8117fb6 (patch) | |
tree | c24bd2e13e6a85992879df33d8f53996e9d87a9e /source/blender | |
parent | bfeef2f5f07094c4014ce7c7bf7e933c168c2bd0 (diff) |
Fix #33628, Segmentation fault after pasting a closed group of nodes into an open group. Finally now there is a proper check for pasting nodes into groups. It uses the poll_instance callback of node types to determine if a node can be added into a specific node tree. Currently this is only implemented for group nodes and does a recursive check to avoid pasting a node group into itself (on any level, also nested groups).
Diffstat (limited to 'source/blender')
5 files changed, 23 insertions, 5 deletions
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index cba807a436f..5faafe7bdce 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -1978,7 +1978,7 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) bNodeLink *link; int num_nodes; float center[2]; - int is_clipboard_valid; + int is_clipboard_valid, all_nodes_valid; /* validate pointers in the clipboard */ is_clipboard_valid = BKE_node_clipboard_validate(); @@ -2000,6 +2000,17 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "Some nodes references could not be restored, will be left empty"); } + /* make sure all clipboard nodes would be valid in the target tree */ + all_nodes_valid = TRUE; + for (node = clipboard_nodes_lb->first; node; node = node->next) { + if (!node->typeinfo->poll_instance(node, ntree)) { + all_nodes_valid = FALSE; + BKE_reportf(op->reports, RPT_ERROR, "Cannot add node %s into node tree %s", node->name, ntree->id.name+2); + } + } + if (!all_nodes_valid) + return OPERATOR_CANCELLED; + ED_preview_kill_jobs(C); /* deselect old nodes */ diff --git a/source/blender/nodes/composite/nodes/node_composite_common.c b/source/blender/nodes/composite/nodes/node_composite_common.c index 44643724073..df1c5d3316b 100644 --- a/source/blender/nodes/composite/nodes/node_composite_common.c +++ b/source/blender/nodes/composite/nodes/node_composite_common.c @@ -51,6 +51,7 @@ void register_node_type_cmp_group(void) node_type_base_custom(&ntype, "CompositorNodeGroup", "Group", NODE_CLASS_GROUP, NODE_OPTIONS | NODE_CONST_OUTPUT); ntype.type = NODE_GROUP; ntype.poll = cmp_node_poll_default; + ntype.poll_instance = node_group_poll_instance; ntype.update_internal_links = node_update_internal_links_default; ntype.ext.srna = RNA_struct_find("CompositorNodeGroup"); BLI_assert(ntype.ext.srna != NULL); diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 4e4443f7c3f..24f35cc81af 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -89,11 +89,15 @@ const char *node_group_label(bNode *node) int node_group_poll_instance(bNode *node, bNodeTree *nodetree) { - bNodeTree *grouptree = (bNodeTree*)node->id; - if (grouptree) - return nodeGroupPoll(nodetree, grouptree); + if (node->typeinfo->poll(node->typeinfo, nodetree)) { + bNodeTree *grouptree = (bNodeTree*)node->id; + if (grouptree) + return nodeGroupPoll(nodetree, grouptree); + else + return TRUE; /* without a linked node tree, group node is always ok */ + } else - return 1; + return FALSE; } int nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree) diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c b/source/blender/nodes/shader/nodes/node_shader_common.c index 155aa508ed9..cd2953c839a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.c +++ b/source/blender/nodes/shader/nodes/node_shader_common.c @@ -231,6 +231,7 @@ void register_node_type_sh_group(void) node_type_base_custom(&ntype, "ShaderNodeGroup", "Group", NODE_CLASS_GROUP, NODE_OPTIONS | NODE_CONST_OUTPUT); ntype.type = NODE_GROUP; ntype.poll = sh_node_poll_default; + ntype.poll_instance = node_group_poll_instance; ntype.update_internal_links = node_update_internal_links_default; ntype.ext.srna = RNA_struct_find("ShaderNodeGroup"); BLI_assert(ntype.ext.srna != NULL); diff --git a/source/blender/nodes/texture/nodes/node_texture_common.c b/source/blender/nodes/texture/nodes/node_texture_common.c index e884d50dc05..ee03323fb5d 100644 --- a/source/blender/nodes/texture/nodes/node_texture_common.c +++ b/source/blender/nodes/texture/nodes/node_texture_common.c @@ -159,6 +159,7 @@ void register_node_type_tex_group(void) node_type_base_custom(&ntype, "TextureNodeGroup", "Group", NODE_CLASS_GROUP, NODE_OPTIONS | NODE_CONST_OUTPUT); ntype.type = NODE_GROUP; ntype.poll = tex_node_poll_default; + ntype.poll_instance = node_group_poll_instance; ntype.update_internal_links = node_update_internal_links_default; ntype.ext.srna = RNA_struct_find("TextureNodeGroup"); BLI_assert(ntype.ext.srna != NULL); |