Fix old files with changed node socket type not loading correctly.

This would lead to sock.default_value pointing to the wrong data type,
possibly causing crashes. Unfortunately, this bug will still exist for
older Blender versions that try to load newer files, which makes
changing the type of a node socket problematic.
This commit is contained in:
Brecht Van Lommel 2018-01-20 01:04:07 +01:00
parent dd35048602
commit e53447c137
Notes: blender-bot 2023-02-14 06:17:13 +01:00
Referenced by issue #53683, 2.79a release
3 changed files with 29 additions and 9 deletions

View File

@ -446,6 +446,7 @@ struct bNodeSocket *nodeInsertStaticSocket(struct bNodeTree *ntree, struct bNode
struct bNodeSocket *next_sock, const char *identifier, const char *name);
void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock);
void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node);
void nodeModifySocketType(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, int type, int subtype);
struct bNode *nodeAddNode(const struct bContext *C, struct bNodeTree *ntree, const char *idname);
struct bNode *nodeAddStaticNode(const struct bContext *C, struct bNodeTree *ntree, int type);

View File

@ -506,6 +506,26 @@ static bNodeSocket *make_socket(bNodeTree *ntree, bNode *UNUSED(node), int in_ou
return sock;
}
void nodeModifySocketType(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock,
int type, int subtype)
{
const char *idname = nodeStaticSocketType(type, subtype);
if (!idname) {
printf("Error: static node socket type %d undefined\n", type);
return;
}
if (sock->default_value) {
MEM_freeN(sock->default_value);
sock->default_value = NULL;
}
sock->type = type;
BLI_strncpy(sock->idname, idname, sizeof(sock->idname));
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(idname));
}
bNodeSocket *nodeAddSocket(bNodeTree *ntree, bNode *node, int in_out, const char *idname,
const char *identifier, const char *name)
{

View File

@ -112,22 +112,21 @@ static bNodeSocket *verify_socket_template(bNodeTree *ntree, bNode *node, int in
break;
}
if (sock) {
sock->type = stemp->type;
if (sock->type != stemp->type) {
nodeModifySocketType(ntree, node, sock, stemp->type, stemp->subtype);
}
sock->limit = (stemp->limit == 0 ? 0xFFF : stemp->limit);
sock->flag |= stemp->flag;
BLI_remlink(socklist, sock);
return sock;
}
else {
/* no socket for this template found, make a new one */
sock = node_add_socket_from_template(ntree, node, stemp, in_out);
/* remove the new socket from the node socket list first,
* will be added back after verification.
*/
BLI_remlink(socklist, sock);
}
/* remove the new socket from the node socket list first,
* will be added back after verification. */
BLI_remlink(socklist, sock);
return sock;
}