diff options
author | Bastien Montagne <bastien@blender.org> | 2021-01-11 18:09:11 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-01-11 18:44:19 +0300 |
commit | 1a26d1576345fb1eb3d31d3048f64b5e4f7a6109 (patch) | |
tree | 021ede378910801ad01f5a76239654403dbc1b7d /source/blender/blenkernel/intern | |
parent | 2f9073adb140e05e0b202d237354a1bbe9d66c69 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 12 |
2 files changed, 8 insertions, 8 deletions
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, |