Bugfix: 'Random' crashes after duplicating bones
authorJoshua Leung <aligorith@gmail.com>
Wed, 4 Jul 2007 07:07:12 +0000 (07:07 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 4 Jul 2007 07:07:12 +0000 (07:07 +0000)
This commit should fix some seemingly random crashes broken and I have been experiencing while editing armatures.

A backtrace revealed that autosave was choking on the PoseChannels that didn't have a Bone assigned to them. This was caused by the bone duplication code making a new PoseChannel for a duplicated bone, but that new bone not getting assigned to the PoseChannel yet, as the user was still in EditMode.

source/blender/blenloader/intern/writefile.c
source/blender/src/editarmature.c

index 2ac3063f2484898286af3d7d987b47e26a6a4ffa..94f51a3c2b1b76902d2c368aafd8d885d26e2107 100644 (file)
@@ -767,21 +767,23 @@ static void write_constraints(WriteData *wd, ListBase *conlist)
 
 static void write_pose(WriteData *wd, bPose *pose)
 {
-       bPoseChannel    *chan;
+       bPoseChannel *chan;
 
        /* Write each channel */
-
        if (!pose)
                return;
 
-       // Write channels
+       /* Write channels */
        for (chan=pose->chanbase.first; chan; chan=chan->next) {
                write_constraints(wd, &chan->constraints);
-               chan->selectflag= chan->bone->flag & (BONE_SELECTED|BONE_ACTIVE); // gets restored on read, for library armatures
+               
+               /* prevent crashes with autosave, when a bone duplicated in editmode has not yet been assigned to its posechannel */
+               if (chan->bone) 
+                       chan->selectflag= chan->bone->flag & (BONE_SELECTED|BONE_ACTIVE); /* gets restored on read, for library armatures */
                writestruct(wd, DATA, "bPoseChannel", 1, chan);
        }
 
-       // Write this pose
+       /* Write this pose */
        writestruct(wd, DATA, "bPose", 1, pose);
 }
 
index 338147827da6a88ece3cebf1e8ccd17d621286c7..949decb117118f062445b4165e53ac317928b68d 100644 (file)
@@ -1615,9 +1615,9 @@ void adduplicate_armature(void)
                                if (!firstDup)
                                        firstDup=eBone;
                                
-                               /* Lets duplicate the list of constraits that the
-                                       * current bone has.
-                                       */
+                               /* Lets duplicate the list of constraints that the
+                                * current bone has.
+                                */
                                if (OBACT->pose) {
                                        bPoseChannel *chanold, *channew;
                                        ListBase     *listold, *listnew;
@@ -1625,7 +1625,10 @@ void adduplicate_armature(void)
                                        chanold = verify_pose_channel (OBACT->pose, curBone->name);
                                        if (chanold) {
                                                listold = &chanold->constraints;
-                                               if (listold){
+                                               if (listold) {
+                                                       /* WARNING: this creates a new posechannel, but there will not be an attached bone 
+                                                        *              yet as the new bones created here are still 'EditBones' not 'Bones'. 
+                                                        */
                                                        channew = 
                                                                verify_pose_channel(OBACT->pose, eBone->name);
                                                        if (channew) {
@@ -1646,7 +1649,6 @@ void adduplicate_armature(void)
                                                }
                                        }
                                }
-
                        }
                }
        }