[Bf-blender-cvs] [76650402f30] master: Fix T69931: Materials with keyframes duplicated by 'make single user' are linked.

Bastien Montagne noreply at git.blender.org
Mon Sep 16 23:08:11 CEST 2019


Commit: 76650402f3004cc833be4b6c55059dd1ddd5a3bf
Author: Bastien Montagne
Date:   Mon Sep 16 22:55:44 2019 +0200
Branches: master
https://developer.blender.org/rB76650402f3004cc833be4b6c55059dd1ddd5a3bf

Fix T69931: Materials with keyframes duplicated by 'make single user' are linked.

Another sneaky bite from the infamous private ID data: While those
monsters are not in bmain, the actions used by their animdata are
regular cute little ID's, living with the herd in the safe and sound
Main DB...

So we have to be careful not to propagate the nasty black magic
required to handle the formers when we duplicate their animdata.

Saying it again: private ID datablocks should never have had their own
animdata & actions, this is endless issue also with RNA paths... And
makes copying of animation between materials and such needlessly
complicated.

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

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 261416dc025..5a4a3f29a93 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -114,7 +114,10 @@ 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, int flag);
+void BKE_libblock_copy_ex(struct Main *bmain,
+                          const struct ID *id,
+                          struct ID **r_newid,
+                          const int orig_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 bbee49e8150..6eb9de7aaf0 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1407,9 +1407,10 @@ 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, int flag)
+void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int orig_flag)
 {
   ID *new_id = *r_newid;
+  int flag = orig_flag;
 
   const bool is_private_id_data = (id->flag & LIB_PRIVATE_DATA) != 0;
 
@@ -1430,7 +1431,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, int flag)
   }
 
   /* The id->flag bits to copy over. */
-  const int copy_flag_mask = LIB_PRIVATE_DATA;
+  const int copy_idflag_mask = LIB_PRIVATE_DATA;
 
   if ((flag & LIB_ID_CREATE_NO_ALLOCATE) != 0) {
     /* r_newid already contains pointer to allocated memory. */
@@ -1454,7 +1455,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, int flag)
     memcpy(cpn + id_offset, cp + id_offset, id_len - id_offset);
   }
 
-  new_id->flag = (new_id->flag & ~copy_flag_mask) | (id->flag & copy_flag_mask);
+  new_id->flag = (new_id->flag & ~copy_idflag_mask) | (id->flag & copy_idflag_mask);
 
   if (id->properties) {
     new_id->properties = IDP_CopyProperty_ex(id->properties, flag);
@@ -1474,9 +1475,12 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, int flag)
 
     /* the duplicate should get a copy of the animdata */
     if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) {
-      BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0 ||
-                 is_private_id_data);
-      iat->adt = BKE_animdata_copy(bmain, iat->adt, flag);
+      /* Note that even though horrors like root nodetrees are not in bmain, the actions they use
+       * in their anim data *are* in bmain... super-mega-hurra. */
+      int animdata_flag = orig_flag;
+      BLI_assert((animdata_flag & LIB_ID_COPY_ACTIONS) == 0 ||
+                 (animdata_flag & LIB_ID_CREATE_NO_MAIN) == 0);
+      iat->adt = BKE_animdata_copy(bmain, iat->adt, animdata_flag);
     }
     else {
       iat->adt = NULL;



More information about the Bf-blender-cvs mailing list