Fix T66991 Crash when deleting edit bones when pchan is referenced by bendybone
authorClément Foucault <foucault.clem@gmail.com>
Mon, 15 Jul 2019 13:13:33 +0000 (15:13 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Mon, 15 Jul 2019 13:13:45 +0000 (15:13 +0200)
This was caused by loose pointers.

This diff takes care of clearing the fields of other bones before deleting the pchan.

Reviewers: brecht, sergey

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D5258

source/blender/blenkernel/intern/action.c

index 6dd4eefc01480386e6dd8c32175c957a378f201d..3e3a533275b648d69edc5969c884ff72bfa7c280 100644 (file)
@@ -729,6 +729,21 @@ void BKE_pose_channels_hash_free(bPose *pose)
   }
 }
 
+static void pose_channels_remove_internal_links(Object *ob, bPoseChannel *unlinked_pchan)
+{
+  LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
+    if (pchan->bbone_prev == unlinked_pchan) {
+      pchan->bbone_prev = NULL;
+    }
+    if (pchan->bbone_next == unlinked_pchan) {
+      pchan->bbone_next = NULL;
+    }
+    if (pchan->custom_tx == unlinked_pchan) {
+      pchan->custom_tx = NULL;
+    }
+  }
+}
+
 /**
  * Selectively remove pose channels.
  */
@@ -747,6 +762,7 @@ void BKE_pose_channels_remove(Object *ob,
       if (filter_fn(pchan->name, user_data)) {
         /* Bone itself is being removed */
         BKE_pose_channel_free(pchan);
+        pose_channels_remove_internal_links(ob, pchan);
         if (ob->pose->chanhash) {
           BLI_ghash_remove(ob->pose->chanhash, pchan->name, NULL, NULL);
         }