diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-02-13 16:58:38 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-02-13 17:02:24 +0300 |
commit | c6e3a20ab60ba8fb56886913a5c7a4269d45b4c3 (patch) | |
tree | 7239c54775856fc07089cbebe409cd8a460e4fca /source | |
parent | 74a3d9b410e671b81b6b41e16dd9b158882521d3 (diff) |
Fix T61506: Wrong user counting with ID properties in pynodes.
Nuke away old nodeCopyNode(), much better to use new BKE_node_copy_ex(),
which behaves as expected for the various optional flags that can be passed.
This also removes the need to handle ID refcounting in calling code
(ugly!) and allows us to remove an even uglier name from our codebase! :D
Note that this fixes three related issues actually, that bug was also
affecting copy/paste of nodes, and 'Separate with copy' operator (the
latter being actually fully wrong, since it was not refcounting
anything, not even node->id pointer...).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 22 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_group.c | 8 |
3 files changed, 11 insertions, 20 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 7061b68e752..5d152569440 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -450,7 +450,6 @@ void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node); void nodeDeleteNode(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node); struct bNode *BKE_node_copy_ex(struct bNodeTree *ntree, struct bNode *node_src, const int flag); -struct bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node); struct bNodeLink *nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock); void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 8321278e058..c14d378e9b7 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -1112,15 +1112,10 @@ static int node_duplicate_exec(bContext *C, wmOperator *op) lastnode = ntree->nodes.last; for (node = ntree->nodes.first; node; node = node->next) { if (node->flag & SELECT) { - newnode = nodeCopyNode(ntree, node); - - if (newnode->id) { - /* simple id user adjustment, node internal functions don't touch this - * but operators and readfile.c do. */ - id_us_plus(newnode->id); - /* to ensure redraws or rerenders happen */ - ED_node_tag_update_id(snode->id); - } + newnode = BKE_node_copy_ex(ntree, node, LIB_ID_COPY_DEFAULT); + + /* to ensure redraws or rerenders happen */ + ED_node_tag_update_id(snode->id); } /* make sure we don't copy new nodes again! */ @@ -1926,8 +1921,8 @@ static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op)) for (node = ntree->nodes.first; node; node = node->next) { if (node->flag & SELECT) { - bNode *new_node; - new_node = nodeCopyNode(NULL, node); + /* No ID refcounting, this node is virtual, detached from any actual Blender data currently. */ + bNode *new_node = BKE_node_copy_ex(ntree, node, LIB_ID_CREATE_NO_USER_REFCOUNT); BKE_node_clipboard_add_node(new_node); } } @@ -2047,10 +2042,7 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) /* copy nodes from clipboard */ for (node = clipboard_nodes_lb->first; node; node = node->next) { - bNode *new_node = nodeCopyNode(ntree, node); - - /* needed since nodeCopyNode() doesn't increase ID's */ - id_us_plus(node->id); + bNode *new_node = BKE_node_copy_ex(ntree, node, LIB_ID_COPY_DEFAULT); /* pasted nodes are selected */ nodeSetSelected(new_node, true); diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index e29d6e054d7..24036a9bf1b 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -404,7 +404,7 @@ static int node_group_separate_selected( for (node = ntree->nodes.first; node; node = node->next) nodeSetSelected(node, false); - /* clear new pointers, set in nodeCopyNode */ + /* clear new pointers, set in BKE_node_copy_ex(). */ for (node = ngroup->nodes.first; node; node = node->next) node->new_node = NULL; @@ -422,7 +422,7 @@ static int node_group_separate_selected( if (make_copy) { /* make a copy */ - newnode = nodeCopyNode(ngroup, node); + newnode = BKE_node_copy_ex(ngroup, node, LIB_ID_COPY_DEFAULT); } else { /* use the existing node */ @@ -541,13 +541,13 @@ static int node_group_separate_exec(bContext *C, wmOperator *op) switch (type) { case NODE_GS_COPY: - if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, 1)) { + if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, true)) { BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes"); return OPERATOR_CANCELLED; } break; case NODE_GS_MOVE: - if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, 0)) { + if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, false)) { BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes"); return OPERATOR_CANCELLED; } |