[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46316] trunk/blender/source/blender: Bugfixes for various ID-block references (Constraints, NLA)

Joshua Leung aligorith at gmail.com
Sat May 5 17:54:09 CEST 2012


Revision: 46316
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46316
Author:   aligorith
Date:     2012-05-05 15:54:08 +0000 (Sat, 05 May 2012)
Log Message:
-----------
Bugfixes for various ID-block references (Constraints, NLA)

* ID-blocks referenced by Constraints but not being used as the target objects
(such as Actions in the Action Constraint, or Text Blocks in PyConstraints) now
get usercounts for being referenced in this way. This should fix ancient bugs
such as [#19205] and [#8593]. More tests still needed to verify that this
does now play nicely with proxies.

* Changing actions used by NLA strips should now update the usercounts
accordingly

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_constraint.h
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesrna/intern/rna_animation.c
    trunk/blender/source/blender/makesrna/intern/rna_constraint.c
    trunk/blender/source/blender/makesrna/intern/rna_nla.c

Modified: trunk/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_constraint.h	2012-05-05 14:52:04 UTC (rev 46315)
+++ trunk/blender/source/blender/blenkernel/BKE_constraint.h	2012-05-05 15:54:08 UTC (rev 46316)
@@ -62,7 +62,7 @@
 /* ---------------------------------------------------------------------------- */
 
 /* Callback format for performing operations on ID-pointers for Constraints */
-typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, void *userdata);
+typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, short isReference, void *userdata);
 
 /* ....... */
 

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2012-05-05 14:52:04 UTC (rev 46315)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2012-05-05 15:54:08 UTC (rev 46316)
@@ -781,7 +781,7 @@
 	bChildOfConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int childof_get_tars (bConstraint *con, ListBase *list)
@@ -917,7 +917,7 @@
 	bTrackToConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int trackto_get_tars (bConstraint *con, ListBase *list)
@@ -1098,10 +1098,10 @@
 	bKinematicConstraint *data= con->data;
 	
 	/* chain target */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 	
 	/* poletarget */
-	func(con, (ID**)&data->poletar, userdata);
+	func(con, (ID**)&data->poletar, FALSE, userdata);
 }
 
 static int kinematic_get_tars (bConstraint *con, ListBase *list)
@@ -1191,7 +1191,7 @@
 	bFollowPathConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int followpath_get_tars (bConstraint *con, ListBase *list)
@@ -1541,7 +1541,7 @@
 	bLocateLikeConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int loclike_get_tars (bConstraint *con, ListBase *list)
@@ -1632,7 +1632,7 @@
 	bChildOfConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int rotlike_get_tars (bConstraint *con, ListBase *list)
@@ -1745,7 +1745,7 @@
 	bSizeLikeConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int sizelike_get_tars (bConstraint *con, ListBase *list)
@@ -1835,7 +1835,7 @@
 	bTransLikeConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int translike_get_tars (bConstraint *con, ListBase *list)
@@ -2007,10 +2007,10 @@
 	
 	/* targets */
 	for (ct= data->targets.first; ct; ct= ct->next)
-		func(con, (ID**)&ct->tar, userdata);
+		func(con, (ID**)&ct->tar, FALSE, userdata);
 		
 	/* script */
-	func(con, (ID**)&data->text, userdata);
+	func(con, (ID**)&data->text, TRUE, userdata);
 }
 
 /* Whether this approach is maintained remains to be seen (aligorith) */
@@ -2107,10 +2107,10 @@
 	bActionConstraint *data= con->data;
 	
 	/* target */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 	
 	/* action */
-	func(con, (ID**)&data->act, userdata);
+	func(con, (ID**)&data->act, TRUE, userdata);
 }
 
 static int actcon_get_tars (bConstraint *con, ListBase *list)
@@ -2273,7 +2273,7 @@
 	bLockTrackConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int locktrack_get_tars (bConstraint *con, ListBase *list)
@@ -2584,7 +2584,7 @@
 	bDistLimitConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int distlimit_get_tars (bConstraint *con, ListBase *list)
@@ -2712,7 +2712,7 @@
 	bStretchToConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int stretchto_get_tars (bConstraint *con, ListBase *list)
@@ -2887,7 +2887,7 @@
 	bMinMaxConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int minmax_get_tars (bConstraint *con, ListBase *list)
@@ -3030,8 +3030,8 @@
 	bRigidBodyJointConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
-	func(con, (ID**)&data->child, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
+	func(con, (ID**)&data->child, FALSE, userdata);
 }
 
 static int rbj_get_tars (bConstraint *con, ListBase *list)
@@ -3083,7 +3083,7 @@
 	bClampToConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int clampto_get_tars (bConstraint *con, ListBase *list)
@@ -3268,7 +3268,7 @@
 	bTransformConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int transform_get_tars (bConstraint *con, ListBase *list)
@@ -3403,10 +3403,10 @@
 
 static void shrinkwrap_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 {
-	bShrinkwrapConstraint *data= con->data;
+	bShrinkwrapConstraint *data = con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->target, userdata);
+	func(con, (ID**)&data->target, FALSE, userdata);
 }
 
 static int shrinkwrap_get_tars (bConstraint *con, ListBase *list)
@@ -3571,7 +3571,7 @@
 	bDampTrackConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int damptrack_get_tars (bConstraint *con, ListBase *list)
@@ -3717,7 +3717,7 @@
 	bSplineIKConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int splineik_get_tars (bConstraint *con, ListBase *list)
@@ -3790,7 +3790,7 @@
 	bPivotConstraint *data= con->data;
 	
 	/* target only */
-	func(con, (ID**)&data->tar, userdata);
+	func(con, (ID**)&data->tar, FALSE, userdata);
 }
 
 static int pivotcon_get_tars (bConstraint *con, ListBase *list)
@@ -3922,9 +3922,9 @@
 {
 	bFollowTrackConstraint *data = con->data;
 
-	func(con, (ID**)&data->clip, userdata);
-	func(con, (ID**)&data->camera, userdata);
-	func(con, (ID**)&data->depth_ob, userdata);
+	func(con, (ID**)&data->clip, TRUE, userdata);
+	func(con, (ID**)&data->camera, FALSE, userdata);
+	func(con, (ID**)&data->depth_ob, FALSE, userdata);
 }
 
 static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
@@ -4116,7 +4116,7 @@
 {
 	bCameraSolverConstraint *data = con->data;
 
-	func(con, (ID**)&data->clip, userdata);
+	func(con, (ID**)&data->clip, TRUE, userdata);
 }
 
 static void camerasolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
@@ -4172,8 +4172,8 @@
 {
 	bObjectSolverConstraint *data= con->data;
 
-	func(con, (ID**)&data->clip, userdata);
-	func(con, (ID**)&data->camera, userdata);
+	func(con, (ID**)&data->clip, FALSE, userdata);
+	func(con, (ID**)&data->camera, FALSE, userdata);
 }
 
 static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
@@ -4535,12 +4535,20 @@
 /* ......... */
 
 /* helper for copy_constraints(), to be used for making sure that ID's are valid */
-static void con_extern_cb(bConstraint *UNUSED(con), ID **idpoin, void *UNUSED(userData))
+static void con_extern_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *UNUSED(userData))
 {
 	if (*idpoin && (*idpoin)->lib)
 		id_lib_extern(*idpoin);
 }
 
+/* helper for copy_constraints(), to be used for making sure that usercounts of copied ID's are fixed up */
+static void con_fix_copied_refs_cb(bConstraint *con, ID **idpoin, short isReference, void *UNUSED(userData))
+{
+	/* increment usercount if this is a reference type */
+	if ((*idpoin) && (isReference))
+		id_us_plus(*idpoin);
+}
+
 /* duplicate all of the constraints in a constraint stack */
 void copy_constraints(ListBase *dst, const ListBase *src, int do_extern)
 {
@@ -4560,6 +4568,10 @@
 			/* perform custom copying operations if needed */
 			if (cti->copy_data)
 				cti->copy_data(con, srccon);
+				
+			/* fix usercounts for all referenced data in referenced data */
+			if (cti->id_looper)
+				cti->id_looper(con, con_fix_copied_refs_cb, NULL);
 			
 			/* for proxies we don't want to make extern */
 			if (do_extern) {

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2012-05-05 14:52:04 UTC (rev 46315)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2012-05-05 15:54:08 UTC (rev 46316)
@@ -2473,10 +2473,19 @@
 	ID *id;
 } tConstraintLinkData;
 /* callback function used to relink constraint ID-links */
-static void lib_link_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, void *userdata)
+static void lib_link_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *userdata)
 {
 	tConstraintLinkData *cld= (tConstraintLinkData *)userdata;
-	*idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin);
+	
+	/* for reference types, we need to increment the usercounts on load... */
+	if (isReference) {
+		/* reference type - with usercount */
+		*idpoin = newlibadr_us(cld->fd, cld->id->lib, *idpoin);
+	}
+	else {
+		/* target type - no usercount needed */
+		*idpoin = newlibadr(cld->fd, cld->id->lib, *idpoin);
+	}
 }
 
 static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
@@ -8115,7 +8124,7 @@
 	Main *mainvar;
 } tConstraintExpandData;
 /* callback function used to expand constraint ID-links */
-static void expand_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, void *userdata)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list