Revision: 15965
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15965
Author:   aligorith
Date:     2008-08-05 05:29:46 +0200 (Tue, 05 Aug 2008)

Log Message:
-----------
Bugfix #16673: Segfault when using Bake Constraints Script

There were several buggy things here (in order of significance):
1) PyAPI method didn't check to make sure that there was an active posechannel 
when deleting posechannel constraints. This was required by 
constraint_active_func() to be able to update the 'active' flags for the 
constraints in that stack
2) PyAPI method removed the links to the constraint data from the constraints 
list, even though that wasn't necessary, and may have caused memory leaks. 
3) constraint_active_func() had no error checking for no constraints-stack 
being found

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Constraint.c
    trunk/blender/source/blender/src/buttons_object.c

Modified: trunk/blender/source/blender/python/api2_2x/Constraint.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Constraint.c    2008-08-05 
02:27:09 UTC (rev 15964)
+++ trunk/blender/source/blender/python/api2_2x/Constraint.c    2008-08-05 
03:29:46 UTC (rev 15965)
@@ -43,6 +43,7 @@
 #include "BKE_constraint.h"
 #include "BLI_blenlib.h"
 #include "BIF_editconstraint.h"
+#include "BIF_poseobject.h"
 #include "BSE_editipo.h"
 #include "MEM_guardedalloc.h"
 #include "butspace.h"
@@ -2286,19 +2287,32 @@
 
 static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, BPy_Constraint 
*value )
 {
-       bConstraint *con = locate_constr( self,  value );
+       bConstraint *con = locate_constr(self, value);
+       bPoseChannel *active= NULL;
 
        /* if we can't locate the constraint, return (exception already set) */
-       if( !con )
+       if (!con)
                return (PyObject *)NULL;
 
-       /* do the actual removal */
-       if( self->pchan )
-               BLI_remlink( &self->pchan->constraints, con );
-       else
-               BLI_remlink( &self->obj->constraints, con);
+       /* check if we need to set temporary 'active' flag for pchan */
+       if (self->pchan) {
+               active= get_active_posechannel(self->obj);
+               
+               if (active != self->pchan) {
+                       if (active) active->bone->flag &= ~BONE_ACTIVE;
+                       self->pchan->bone->flag |= BONE_ACTIVE;
+               }
+       }
+       
+       /* del_constr_func() frees constraint + its data */
        del_constr_func( self->obj, con );
 
+       /* reset active pchan (if applicable) */
+       if (self->pchan && self->pchan!=active) {
+               if (active) active->bone->flag |= BONE_ACTIVE;
+               self->pchan->bone->flag &= ~BONE_ACTIVE;
+       }
+       
        /* erase the link to the constraint */
        value->con = NULL;
 

Modified: trunk/blender/source/blender/src/buttons_object.c
===================================================================
--- trunk/blender/source/blender/src/buttons_object.c   2008-08-05 02:27:09 UTC 
(rev 15964)
+++ trunk/blender/source/blender/src/buttons_object.c   2008-08-05 03:29:46 UTC 
(rev 15965)
@@ -173,6 +173,7 @@
        }
        
        lb= get_active_constraints(ob);
+       if (lb == NULL) return;
        
        for(con= lb->first; con; con= con->next) {
                if(con==con_v) con->flag |= CONSTRAINT_ACTIVE;
@@ -307,7 +308,7 @@
        }
        /* remove constraint itself */
        lb= get_active_constraints(ob_v);
-       free_constraint_data (con);
+       free_constraint_data(con);
        BLI_freelinkN(lb, con);
        
        constraint_active_func(ob_v, NULL);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to