From 8542d97f73f99b1fad24f51a94bf08d44d4879d1 Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Wed, 8 May 2013 15:41:01 +0000 Subject: [PATCH] 2 fixes for node group node_tree pointer property: Make sure the nodeGroupPoll function (which checks for recursion) is used both in the poll callback as well as the actual pointer assignment (set). The poll callback doesn't seem to be used when directly setting the node_tree pointer from the API, so to make sure no dangerous recursion situation can happen this needs a second check. --- source/blender/makesrna/intern/rna_nodetree.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 3a6cb60d18b..7bee0565c93 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -2364,13 +2364,26 @@ static void rna_NodeGroup_update(Main *bmain, Scene *UNUSED(scene), PointerRNA * ED_node_tag_update_nodetree(bmain, ntree); } +static void rna_NodeGroup_node_tree_set(PointerRNA *ptr, const PointerRNA value) +{ + bNodeTree *ntree = ptr->id.data; + bNode *node = ptr->data; + bNodeTree *ngroup = value.data; + + if (nodeGroupPoll(ntree, ngroup)) + node->id = &ngroup->id; +} + static int rna_NodeGroup_node_tree_poll(PointerRNA *ptr, const PointerRNA value) { - bNodeTree *ntree = (bNodeTree *)ptr->id.data; - bNodeTree *ngroup = (bNodeTree *)value.data; + bNodeTree *ntree = ptr->id.data; + bNodeTree *ngroup = value.data; /* only allow node trees of the same type as the group node's tree */ - return (ngroup->type == ntree->type); + if (ngroup->type != ntree->type) + return false; + + return nodeGroupPoll(ntree, ngroup); } @@ -2838,7 +2851,7 @@ static void def_group(StructRNA *srna) prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "id"); RNA_def_property_struct_type(prop, "NodeTree"); - RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_NodeGroup_node_tree_poll"); + RNA_def_property_pointer_funcs(prop, NULL, "rna_NodeGroup_node_tree_set", NULL, "rna_NodeGroup_node_tree_poll"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Node Tree", ""); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeGroup_update");