From 4b7930dbbd8a11fb5db3e1cc81ca9ca5b0a69fc0 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Mon, 17 Jan 2011 15:16:08 +0000 Subject: [PATCH] Bugfix #25681 Python API allowed to make links with input->output reversed. Now node api checks for this case and flips order. --- source/blender/blenkernel/intern/node.c | 58 +++++++++++++++++-- source/blender/makesrna/intern/rna_nodetree.c | 13 +++-- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index c4d54cd6296..fd0edd83c7d 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1082,15 +1082,61 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node, int internal) return nnode; } +/* fromsock and tosock can be NULL */ +/* also used via rna api, so we check for proper input output direction */ bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, bNode *tonode, bNodeSocket *tosock) { - bNodeLink *link= MEM_callocN(sizeof(bNodeLink), "link"); + bNodeSocket *sock; + bNodeLink *link= NULL; + int from= 0, to= 0; - BLI_addtail(&ntree->links, link); - link->fromnode= fromnode; - link->fromsock= fromsock; - link->tonode= tonode; - link->tosock= tosock; + if(fromsock) { + /* test valid input */ + for(sock= fromnode->outputs.first; sock; sock= sock->next) + if(sock==fromsock) + break; + if(sock) + from= 1; /* OK */ + else { + for(sock= fromnode->inputs.first; sock; sock= sock->next) + if(sock==fromsock) + break; + if(sock) + from= -1; /* OK but flip */ + } + } + if(tosock) { + for(sock= tonode->inputs.first; sock; sock= sock->next) + if(sock==tosock) + break; + if(sock) + to= 1; /* OK */ + else { + for(sock= tonode->outputs.first; sock; sock= sock->next) + if(sock==tosock) + break; + if(sock) + to= -1; /* OK but flip */ + } + } + + /* this allows NULL sockets to work */ + if(from >= 0 && to >= 0) { + link= MEM_callocN(sizeof(bNodeLink), "link"); + BLI_addtail(&ntree->links, link); + link->fromnode= fromnode; + link->fromsock= fromsock; + link->tonode= tonode; + link->tosock= tosock; + } + else if(from <= 0 && to <= 0) { + link= MEM_callocN(sizeof(bNodeLink), "link"); + BLI_addtail(&ntree->links, link); + link->fromnode= tonode; + link->fromsock= tosock; + link->tonode= fromnode; + link->tosock= fromsock; + } return link; } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 9d4575b2f43..5c962145c55 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -524,15 +524,16 @@ static bNodeLink *rna_NodeTree_link_new(bNodeTree *ntree, ReportList *reports, b nodeRemSocketLinks(ntree, out); ret= nodeAddLink(ntree, fromnode, in, tonode, out); + + if(ret) { + NodeTagChanged(ntree, tonode); - NodeTagChanged(ntree, tonode); + nodeVerifyGroup(ntree); /* update group node socket links*/ - nodeVerifyGroup(ntree); /* update group node socket links*/ - - ntreeSolveOrder(ntree); - - WM_main_add_notifier(NC_NODE|NA_EDITED, ntree); + ntreeSolveOrder(ntree); + WM_main_add_notifier(NC_NODE|NA_EDITED, ntree); + } return ret; }