Now there is an extra function BKE_libblock_free_data, which is called explicitly in ntreeFreeTree if the tree is not part of the library data (ntreeCopyTree does a similar thing using BKE_libblock_copy_data).
void BKE_libblock_free(struct ListBase *lb, void *idv);
void BKE_libblock_free_us(struct ListBase *lb, void *idv);
+void BKE_libblock_free_data(struct ID *id);
void free_main(struct Main *mainvar);
void tag_main_idcode(struct Main *mainvar, const short type, const short tag);
}
}
+void BKE_libblock_free_data(ID *id)
+{
+ Main *bmain = G.main; /* should eventually be an arg */
+
+ if (id->properties) {
+ IDP_FreeProperty(id->properties);
+ MEM_freeN(id->properties);
+ }
+
+ /* this ID may be a driver target! */
+ BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id);
+}
/* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */
void BKE_libblock_free(ListBase *lb, void *idv)
break;
}
- if (id->properties) {
- IDP_FreeProperty(id->properties);
- MEM_freeN(id->properties);
- }
-
BLI_remlink(lb, id);
- /* this ID may be a driver target! */
- BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id);
+ BKE_libblock_free_data(id);
MEM_freeN(id);
}
/* do not free ntree itself here, BKE_libblock_free calls this function too */
void ntreeFreeTree_ex(bNodeTree *ntree, const short do_id_user)
{
+ bNodeTree *tntree;
bNode *node, *next;
bNodeSocket *sock;
for (sock = ntree->outputs.first; sock; sock = sock->next)
node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&ntree->outputs);
+
+ /* if ntree is not part of library, free the libblock data explicitly */
+ for (tntree = G.main->nodetree.first; tntree; tntree = tntree->id.next)
+ if (tntree == ntree)
+ break;
+ if (tntree == NULL) {
+ BKE_libblock_free_data(&ntree->id);
+ }
}
/* same as ntreeFreeTree_ex but always manage users */
void ntreeFreeTree(bNodeTree *ntree)