[Bf-blender-cvs] [1a26d157634] master: Fix Embedded IDs creation bypassing ID management completely.

Bastien Montagne noreply at git.blender.org
Mon Jan 11 16:50:18 CET 2021


Commit: 1a26d1576345fb1eb3d31d3048f64b5e4f7a6109
Author: Bastien Montagne
Date:   Mon Jan 11 16:09:11 2021 +0100
Branches: master
https://developer.blender.org/rB1a26d1576345fb1eb3d31d3048f64b5e4f7a6109

Fix Embedded IDs creation bypassing ID management completely.

No ID (even remotely) related to Main database should ever be created
directly through MEM_mallocN. Using `BKE_libblock_alloc` is the bare
minimum.

Note that there is no behavior change expected here.

===================================================================

M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/node.c

===================================================================

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index a553552f099..58ce7227398 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -829,8 +829,8 @@ Base *BKE_collection_or_layer_objects(const ViewLayer *view_layer, Collection *c
 Collection *BKE_collection_master_add()
 {
   /* Not an actual datablock, but owned by scene. */
-  Collection *master_collection = MEM_callocN(sizeof(Collection), "Master Collection");
-  STRNCPY(master_collection->id.name, "GRMaster Collection");
+  Collection *master_collection = BKE_libblock_alloc(
+      NULL, ID_GR, "Master Collection", LIB_ID_CREATE_NO_MAIN);
   master_collection->id.flag |= LIB_EMBEDDED_DATA;
   master_collection->flag |= COLLECTION_IS_MASTER;
   master_collection->color_tag = COLLECTION_COLOR_NONE;
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 5d3994068ec..ad90c0fe82e 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -2322,14 +2322,14 @@ bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname)
   /* trees are created as local trees for compositor, material or texture nodes,
    * node groups and other tree types are created as library data.
    */
-  if (bmain) {
-    ntree = BKE_libblock_alloc(bmain, ID_NT, name, 0);
+  const bool is_embedded = (bmain == NULL);
+  int flag = 0;
+  if (is_embedded) {
+    flag |= LIB_ID_CREATE_NO_MAIN;
   }
-  else {
-    ntree = MEM_callocN(sizeof(bNodeTree), "new node tree");
+  ntree = BKE_libblock_alloc(bmain, ID_NT, name, flag);
+  if (is_embedded) {
     ntree->id.flag |= LIB_EMBEDDED_DATA;
-    *((short *)ntree->id.name) = ID_NT;
-    BLI_strncpy(ntree->id.name + 2, name, sizeof(ntree->id.name));
   }
 
   /* Types are fully initialized at this point,



More information about the Bf-blender-cvs mailing list