[Bf-blender-cvs] [022ad8f7699] id_copy_refactor: Change a bit ideas behind new copying code, now ID-specific copying never handles usercount.

Bastien Montagne noreply at git.blender.org
Thu Jul 6 15:47:48 CEST 2017


Commit: 022ad8f769919c0e703bce14bd04b68888ccdb77
Author: Bastien Montagne
Date:   Thu Jul 6 15:46:14 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB022ad8f769919c0e703bce14bd04b68888ccdb77

Change a bit ideas behind new copying code, now ID-specific copying never handles usercount.

Makes things much simpler, and more consistent.

Also fix issue with new copying and bloody nodetrees, using same hack as
in original ntree copying code to detect 'root' ntrees that shall never
be put into bmain :(((((((

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

M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/mball.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/node.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/speaker.c

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

diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 273f5eeb2d4..0261e623be4 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -180,20 +180,25 @@ static void copy_bonechildren(
  * Only copy internal data of Armature ID from source to already allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
  *
+ * WARNING! This function will not handle ID user count!
+ *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
-void BKE_armature_copy_ex(Main *bmain, bArmature *arm_dst, const bArmature *arm_src, const int flag)
+void BKE_armature_copy_ex(Main *UNUSED(bmain), bArmature *arm_dst, const bArmature *arm_src, const int flag)
 {
 	Bone *bone_src, *bone_dst;
 	Bone *bone_dst_act = NULL;
 
+	/* We never handle usercount here for own data. */
+	const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT;
+
 	BLI_duplicatelist(&arm_dst->bonebase, &arm_src->bonebase);
 
 	/* Duplicate the childrens' lists */
 	bone_dst = arm_dst->bonebase.first;
 	for (bone_src = arm_src->bonebase.first; bone_src; bone_src = bone_src->next) {
 		bone_dst->parent = NULL;
-		copy_bonechildren(bone_dst, bone_src, arm_src->act_bone, &bone_dst_act, flag);
+		copy_bonechildren(bone_dst, bone_src, arm_src->act_bone, &bone_dst_act, flag_subdata);
 		bone_dst = bone_dst->next;
 	}
 
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 8cadb933f78..6406f514f34 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -97,6 +97,8 @@ void *BKE_camera_add(Main *bmain, const char *name)
  * Only copy internal data of Camera ID from source to already allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
  *
+ * WARNING! This function will not handle ID user count!
+ *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
 void BKE_camera_copy_ex(Main *UNUSED(bmain), Camera *UNUSED(cam_dst), const Camera *UNUSED(cam_src), const int UNUSED(flag))
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index aa023750328..79d4c1264b0 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -191,21 +191,16 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
  * Only copy internal data of Curve ID from source to already allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
  *
+ * WARNING! This function will not handle ID user count!
+ *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
 void BKE_curve_copy_ex(Main *bmain, Curve *cu_dst, const Curve *cu_src, const int flag)
 {
-	int a;
-
 	BLI_listbase_clear(&cu_dst->nurb);
 	BKE_nurbList_duplicate(&(cu_dst->nurb), &(cu_src->nurb));
 
 	cu_dst->mat = MEM_dupallocN(cu_src->mat);
-	if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
-		for (a = 0; a < cu_dst->totcol; a++) {
-			id_us_plus((ID *)cu_dst->mat[a]);
-		}
-	}
 
 	cu_dst->str = MEM_dupallocN(cu_src->str);
 	cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo);
@@ -218,13 +213,6 @@ void BKE_curve_copy_ex(Main *bmain, Curve *cu_dst, const Curve *cu_src, const in
 
 	cu_dst->editnurb = NULL;
 	cu_dst->editfont = NULL;
-
-	if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
-		id_us_plus((ID *)cu_dst->vfont);
-		id_us_plus((ID *)cu_dst->vfontb);
-		id_us_plus((ID *)cu_dst->vfonti);
-		id_us_plus((ID *)cu_dst->vfontbi);
-	}
 }
 
 Curve *BKE_curve_copy(Main *bmain, const Curve *cu)
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index ce186c1fd4e..683723d9415 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -155,6 +155,8 @@ Key *BKE_key_add(ID *id)    /* common function */
  * Only copy internal data of ShapeKey ID from source to already allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
  *
+ * WARNING! This function will not handle ID user count!
+ *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
 void BKE_key_copy_ex(Main *UNUSED(bmain), Key *key_dst, const Key *key_src, const int UNUSED(flag))
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index d15bf50ebce..1bee024d0f9 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -120,6 +120,8 @@ Lamp *BKE_lamp_add(Main *bmain, const char *name)
  * Only copy internal data of Lamp ID from source to already allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
  *
+ * WARNING! This function will not handle ID user count!
+ *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
 void BKE_lamp_copy_ex(Main *bmain, Lamp *la_dst, const Lamp *la_src, const int flag)
@@ -130,16 +132,14 @@ void BKE_lamp_copy_ex(Main *bmain, Lamp *la_dst, const Lamp *la_src, const int f
 		if (la_dst->mtex[a]) {
 			la_dst->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex");
 			memcpy(la_dst->mtex[a], la_src->mtex[a], sizeof(MTex));
-			if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
-				id_us_plus((ID *)la_dst->mtex[a]->tex);
-			}
 		}
 	}
-	
+
 	la_dst->curfalloff = curvemapping_copy(la_src->curfalloff);
 
-	if (la_src->nodetree)
-		la_dst->nodetree = ntreeCopyTree(bmain, la_src->nodetree);  /* XXX TODO Replace this! */
+	if (la_src->nodetree) {
+		BKE_id_copy_ex(bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag, false);
+	}
 
 	if ((flag & LIB_ID_COPY_NO_PREVIEW) != 1) {
 		BKE_previewimg_id_copy(&la_dst->id, &la_src->id);
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 931b6a353d1..a11674ed2ce 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -281,6 +281,8 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name)
  * Only copy internal data of Lattice ID from source to already allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
  *
+ * WARNING! This function will not handle ID user count!
+ *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
 void BKE_lattice_copy_ex(Main *bmain, Lattice *lt_dst, const Lattice *lt_src, const int flag)
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 03687846eeb..78c42dd88b5 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -526,10 +526,6 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 /* XXX TODO remove test thing, *all* IDs should be copyable that way! */
 bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test)
 {
-	/* We handle usercount ousrselves in post-copy processing.
-	 * Ideally, usercount should never be handled by IDType-specific copying code, but for now let's allow it... */
-	const int flag_idtype_copy = flag | LIB_ID_COPY_NO_USER_REFCOUNT;
-
 #define ITEMS_IMPLEMENTED ID_OB, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_SPK, ID_CA, ID_KE, ID_AR, ID_NT
 
 	if (!test) {
@@ -541,16 +537,16 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 
 	switch ((ID_Type)GS(id->name)) {
 		case ID_OB:
-			if (!test) BKE_object_copy_ex(bmain, (Object *)*r_newid, (Object *)id, flag_idtype_copy);
+			if (!test) BKE_object_copy_ex(bmain, (Object *)*r_newid, (Object *)id, flag);
 			break;
 		case ID_ME:
-			if (!test) BKE_mesh_copy_ex(bmain, (Mesh *)*r_newid, (Mesh *)id, flag_idtype_copy);
+			if (!test) BKE_mesh_copy_ex(bmain, (Mesh *)*r_newid, (Mesh *)id, flag);
 			break;
 		case ID_CU:
-			if (!test) BKE_curve_copy_ex(bmain, (Curve *)*r_newid, (Curve *)id, flag_idtype_copy);
+			if (!test) BKE_curve_copy_ex(bmain, (Curve *)*r_newid, (Curve *)id, flag);
 			break;
 		case ID_MB:
-			if (!test) BKE_mball_copy_ex(bmain, (MetaBall *)*r_newid, (MetaBall *)id, flag_idtype_copy);
+			if (!test) BKE_mball_copy_ex(bmain, (MetaBall *)*r_newid, (MetaBall *)id, flag);
 			break;
 		case ID_MA:
 			if (!test) *r_newid = (ID *)BKE_material_copy(bmain, (Material *)id);
@@ -562,19 +558,19 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) *r_newid = (ID *)BKE_image_copy(bmain, (Image *)id);
 			break;
 		case ID_LT:
-			if (!test) BKE_lattice_copy_ex(bmain, (Lattice *)*r_newid, (Lattice *)id, flag_idtype_copy);
+			if (!test) BKE_lattice_copy_ex(bmain, (Lattice *)*r_newid, (Lattice *)id, flag);
 			break;
 		case ID_LA:
-			if (!test) BKE_lamp_copy_ex(bmain, (Lamp *)*r_newid, (Lamp *)id, flag_idtype_copy);
+			if (!test) BKE_lamp_copy_ex(bmain, (Lamp *)*r_newid, (Lamp *)id, flag);
 			break;
 		case ID_SPK:
-			if (!test) BKE_speaker_copy_ex(bmain, (Speaker *)*r_newid, (Speaker *)id, flag_idtype_copy);
+			if (!test) BKE_speaker_copy_ex(bmain, (Speaker *)*r_newid, (Speaker *)id, flag);
 			break;
 		case ID_CA:
-			if (!test) BKE_camera_copy_ex(bmain, (Camera *)*r_newid, (Camera *)id, flag_idtype_copy);
+			if (!test) BKE_camera_copy_ex(bmain, (Camera *)*r_newid, (Camera *)id, flag);
 			break;
 		case ID_KE:
-			if (!test) BKE_key_copy_ex(bmain, (Key *)*r_newid, (Key *)id, flag_idtype_copy);
+			if (!test) BKE_key_copy_ex(bmain, (Key *)*r_newid, (Key *)id, flag);
 			break;
 		case ID_WO:
 			if (!test) *r_newid = (ID *)BKE_world_copy(bmain, (World *)id);
@@ -586,13 +582,13 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) *r_newid = (ID *)BKE_group_copy(bmain, (Group *)id);
 			break;
 		cas

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list