Commit: f1a805ef918eab85d1c9ba2d7a33b9c127cfbf14 Author: Jacques Lucke Date: Thu Feb 20 11:21:46 2020 +0100 Branches: simulation-tree https://developer.blender.org/rBf1a805ef918eab85d1c9ba2d7a33b9c127cfbf14
unify node type freeing =================================================================== M source/blender/blenkernel/BKE_node.h M source/blender/blenkernel/intern/node.c M source/blender/makesrna/intern/rna_nodetree.c M source/blender/nodes/intern/node_common.c =================================================================== diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index ae32093674b..ffc2150516e 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -177,7 +177,6 @@ typedef int (*NodeGPUExecFunction)(struct GPUMaterial *mat, */ typedef struct bNodeType { void *next, *prev; - short needs_free; /* set for allocated types that need to be freed */ char idname[64]; /* identifier name */ int type; @@ -259,7 +258,8 @@ typedef struct bNodeType { /* Custom data that can be used in callbacks. */ void *userdata; - void (*free_userdata)(void *userdata); + + void (*free_self)(struct bNodeType *ntype); /* **** execution callbacks **** */ NodeInitExecFunction initexecfunc; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 4c66da6eed8..9e52f7ea939 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -412,8 +412,9 @@ static void node_free_type(void *nodetype_v) free_dynamic_typeinfo(nodetype); } - if (nodetype->needs_free) { - MEM_freeN(nodetype); + /* Can be NULL when the type is not dynamically allocated. */ + if (nodetype->free_self) { + nodetype->free_self(nodetype); } } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index db2315ea804..86162539a93 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1682,8 +1682,7 @@ static bNodeType *rna_Node_register_base(Main *bmain, /* create a new node type */ nt = MEM_callocN(sizeof(bNodeType), "node type"); memcpy(nt, &dummynt, sizeof(dummynt)); - /* make sure the node type struct is freed on unregister */ - nt->needs_free = 1; + nt->free_self = (void (*)(bNodeType *))MEM_freeN; nt->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, nt->idname, basetype); nt->ext.data = data; diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 6b3e378c94e..ba00190b1da 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -208,13 +208,13 @@ void register_node_type_frame(void) { /* frame type is used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); + ntype->free_self = (void (*)(bNodeType *))MEM_freeN; node_type_base(ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT, NODE_BACKGROUND); node_type_init(ntype, node_frame_init); node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage); node_type_size(ntype, 150, 100, 0); - ntype->needs_free = 1; nodeRegisterType(ntype); } @@ -253,12 +253,12 @@ void register_node_type_reroute(void) { /* frame type is used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "frame node type"); + ntype->free_self = (void (*)(bNodeType *))MEM_freeN; node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); node_type_init(ntype, node_reroute_init); node_type_internal_links(ntype, node_reroute_update_internal_links); - ntype->needs_free = 1; nodeRegisterType(ntype); } @@ -491,13 +491,13 @@ void register_node_type_group_input(void) { /* used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); + ntype->free_self = (void (*)(bNodeType *))MEM_freeN; node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE, 0); node_type_size(ntype, 140, 80, 400); node_type_init(ntype, node_group_input_init); node_type_update(ntype, node_group_input_update); - ntype->needs_free = 1; nodeRegisterType(ntype); } @@ -589,12 +589,12 @@ void register_node_type_group_output(void) { /* used for all tree types, needs dynamic allocation */ bNodeType *ntype = MEM_callocN(sizeof(bNodeType), "node type"); + ntype->free_self = (void (*)(bNodeType *))MEM_freeN; node_type_base(ntype, NODE_GROUP_OUTPUT, "Group Output", NODE_CLASS_INTERFACE, 0); node_type_size(ntype, 140, 80, 400); node_type_init(ntype, node_group_output_init); node_type_update(ntype, node_group_output_update); - ntype->needs_free = 1; nodeRegisterType(ntype); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs