[Bf-blender-cvs] [0ebc76354f8] master: DatablockManagement: Cleanup logic of private IDs handling in `BKE_libblock_copy_ex()`.

Bastien Montagne noreply at git.blender.org
Mon Sep 2 18:49:13 CEST 2019


Commit: 0ebc76354f8d3bc2bd346a3736f865f6f7faf6e7
Author: Bastien Montagne
Date:   Mon Sep 2 14:18:12 2019 +0200
Branches: master
https://developer.blender.org/rB0ebc76354f8d3bc2bd346a3736f865f6f7faf6e7

DatablockManagement: Cleanup logic of private IDs handling in `BKE_libblock_copy_ex()`.

Now that we have the private ID data flag, we can be more simple *and*
generic here.

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/library.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index c8d85cd0c87..261416dc025 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -114,10 +114,7 @@ enum {
                          LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_CACHES,
 };
 
-void BKE_libblock_copy_ex(struct Main *bmain,
-                          const struct ID *id,
-                          struct ID **r_newid,
-                          const int flag);
+void BKE_libblock_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, int flag);
 void *BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSED_RESULT
     ATTR_NONNULL();
 /* Special version. sued by datablock localization. */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 5dbc9c318a3..f45eba2b53f 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1408,24 +1408,24 @@ void *BKE_id_new_nomain(const short type, const char *name)
   return id;
 }
 
-void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
+void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, int flag)
 {
   ID *new_id = *r_newid;
 
-  /* Grrrrrrrrr... Not adding 'root' nodetrees to bmain.... grrrrrrrrrrrrrrrrrrrr! */
-  /* This is taken from original ntree copy code, might be weak actually? */
-  const bool use_nodetree_alloc_exception = ((GS(id->name) == ID_NT) && (bmain != NULL) &&
-                                             (BLI_findindex(&bmain->nodetrees, id) < 0));
-
-  /* The id->flag bits to copy over. */
-  const int copy_flag_mask = LIB_PRIVATE_DATA;
-
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL);
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0);
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0);
   /* Never implicitly copy shapekeys when generating temp data outside of Main database. */
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_COPY_SHAPEKEY) == 0);
 
+  /* 'Private ID' data handling. */
+  if ((bmain != NULL) && (id->flag & LIB_PRIVATE_DATA) != 0) {
+    flag |= LIB_ID_CREATE_NO_MAIN;
+  }
+
+  /* The id->flag bits to copy over. */
+  const int copy_flag_mask = LIB_PRIVATE_DATA;
+
   if ((flag & LIB_ID_CREATE_NO_ALLOCATE) != 0) {
     /* r_newid already contains pointer to allocated memory. */
     /* TODO do we want to memset(0) whole mem before filling it? */
@@ -1435,10 +1435,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla
     /* TODO Do we want/need to copy more from ID struct itself? */
   }
   else {
-    new_id = BKE_libblock_alloc(bmain,
-                                GS(id->name),
-                                id->name + 2,
-                                flag | (use_nodetree_alloc_exception ? LIB_ID_CREATE_NO_MAIN : 0));
+    new_id = BKE_libblock_alloc(bmain, GS(id->name), id->name + 2, flag);
   }
   BLI_assert(new_id != NULL);



More information about the Bf-blender-cvs mailing list