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.
This commit is contained in:
Bastien Montagne 2021-01-11 16:09:11 +01:00
parent 2f9073adb1
commit 1a26d15763
2 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -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,