Fix for #34756 and #34810, crashes when dropping nodes onto noodles and a related forward compatibility bug.

Added a sanity check to the ED_node_link_insert function to ensure it exits gracefully if no suitable sockets can be found. This was the problem with custom pynodes, which don't define the 'type' DNA of old sockets. The operator will have to be generalized for future nodes, but for now just not crashing seems good enough.

Script node crashes in #34810 were caused by uninitialized 'type' integer as well. This is now done in the set_typeinfo function for sockets (like for trees and nodes too), to avoid any potential remaining issues of this kind. Note that new files need to be loaded and saved again once to be forward compatible again.
This commit is contained in:
Lukas Toenne 2013-04-02 11:59:27 +00:00
parent 37bf7dd98a
commit 8abfaf880d
2 changed files with 22 additions and 13 deletions

@ -190,7 +190,10 @@ static void node_socket_set_typeinfo(bNodeTree *ntree, bNodeSocket *sock, bNodeS
{
if (typeinfo) {
sock->typeinfo = typeinfo;
/* deprecated integer type */
sock->type = typeinfo->type;
if (sock->default_value == NULL) {
/* initialize the default_value pointer used by standard socket types */
node_socket_init_default_value(sock);

@ -1408,17 +1408,23 @@ void ED_node_link_insert(ScrArea *sa)
break;
if (link) {
node = link->tonode;
sockto = link->tosock;
link->tonode = select;
link->tosock = socket_best_match(&select->inputs);
node_remove_extra_links(snode, link->tosock, link);
link->flag &= ~NODE_LINKFLAG_HILITE;
nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs), node, sockto);
ntreeUpdateTree(snode->edittree); /* needed for pointers */
snode_update(snode, select);
ED_node_tag_update_id(snode->id);
bNodeSocket *best_input = socket_best_match(&select->inputs);
bNodeSocket *best_output = socket_best_match(&select->outputs);
if (best_input && best_output) {
node = link->tonode;
sockto = link->tosock;
link->tonode = select;
link->tosock = best_input;
node_remove_extra_links(snode, link->tosock, link);
link->flag &= ~NODE_LINKFLAG_HILITE;
nodeAddLink(snode->edittree, select, best_output, node, sockto);
ntreeUpdateTree(snode->edittree); /* needed for pointers */
snode_update(snode, select);
ED_node_tag_update_id(snode->id);
}
}
}