From 6eb2f71875c69f5f6073fed2d285fe8ef662ba03 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 28 Apr 2021 13:20:12 +1000 Subject: Fix T87631: Crash undoing edit-mode bone duplication Edit mode could leave pose channels in the object that didn't have an associated bone. These are now cleared when freeing edit-mode data. --- source/blender/blenkernel/BKE_armature.h | 1 + source/blender/blenkernel/intern/armature.c | 22 +++++++++++++--------- source/blender/editors/object/object_edit.c | 7 +++++++ source/blender/editors/util/ed_util.c | 1 + 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 0bd817f0da1..3002a9cc10d 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -178,6 +178,7 @@ void BKE_armature_where_is_bone(struct Bone *bone, void BKE_pose_clear_pointers(struct bPose *pose); void BKE_pose_remap_bone_pointers(struct bArmature *armature, struct bPose *pose); void BKE_pchan_rebuild_bbone_handles(struct bPose *pose, struct bPoseChannel *pchan); +void BKE_pose_channels_clear_with_null_bone(struct bPose *pose, const bool do_id_user); void BKE_pose_rebuild(struct Main *bmain, struct Object *ob, struct bArmature *arm, diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index a1ebec1d756..da8a3b49f3c 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2515,6 +2515,17 @@ void BKE_pchan_rebuild_bbone_handles(bPose *pose, bPoseChannel *pchan) pchan->bbone_next = pose_channel_find_bone(pose, pchan->bone->bbone_next); } +void BKE_pose_channels_clear_with_null_bone(bPose *pose, const bool do_id_user) +{ + LISTBASE_FOREACH_MUTABLE (bPoseChannel *, pchan, &pose->chanbase) { + if (pchan->bone == NULL) { + BKE_pose_channel_free_ex(pchan, do_id_user); + BKE_pose_channels_hash_free(pose); + BLI_freelinkN(&pose->chanbase, pchan); + } + } +} + /** * Only after leave editmode, duplicating, validating older files, library syncing. * @@ -2526,7 +2537,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ { Bone *bone; bPose *pose; - bPoseChannel *pchan, *next; + bPoseChannel *pchan; int counter = 0; /* only done here */ @@ -2549,14 +2560,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ } /* and a check for garbage */ - for (pchan = pose->chanbase.first; pchan; pchan = next) { - next = pchan->next; - if (pchan->bone == NULL) { - BKE_pose_channel_free_ex(pchan, do_id_user); - BKE_pose_channels_hash_free(pose); - BLI_freelinkN(&pose->chanbase, pchan); - } - } + BKE_pose_channels_clear_with_null_bone(pose, do_id_user); BKE_pose_channels_hash_make(pose); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 0894314328e..196b330179b 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -55,6 +55,7 @@ #include "IMB_imbuf_types.h" #include "BKE_anim_visualization.h" +#include "BKE_armature.h" #include "BKE_collection.h" #include "BKE_constraint.h" #include "BKE_context.h" @@ -578,6 +579,12 @@ static bool ED_object_editmode_load_free_ex(Main *bmain, if (free_data) { ED_armature_edit_free(obedit->data); + + if (load_data == false) { + /* Don't keep unused pose channels created by duplicating bones + * which may have been deleted/undone, see: T87631. */ + BKE_pose_channels_clear_with_null_bone(obedit->pose, true); + } } /* TODO(sergey): Pose channels might have been changed, so need * to inform dependency graph about this. But is it really the diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index b80782b51be..a1ff6326644 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -33,6 +33,7 @@ #include "BLT_translation.h" +#include "BKE_armature.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_material.h" -- cgit v1.2.3 From 2bf3a960bd2bf2105083b02b757ef2f58336fcb9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 28 Apr 2021 13:26:58 +1000 Subject: Remove include accidentally added in 6eb2f71875c69f5f6073fed2d285fe8ef662ba03 --- source/blender/editors/util/ed_util.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index a1ff6326644..b80782b51be 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -33,7 +33,6 @@ #include "BLT_translation.h" -#include "BKE_armature.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_material.h" -- cgit v1.2.3 From 28828e0041f8d292723796bc3787bd1b3d372a95 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 28 Apr 2021 13:26:58 +1000 Subject: Add NULL check to Object.pose from 6eb2f71875c69f5f6073fed2d285fe8ef662ba03 --- source/blender/editors/object/object_edit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 196b330179b..07c8e7725e3 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -583,7 +583,9 @@ static bool ED_object_editmode_load_free_ex(Main *bmain, if (load_data == false) { /* Don't keep unused pose channels created by duplicating bones * which may have been deleted/undone, see: T87631. */ - BKE_pose_channels_clear_with_null_bone(obedit->pose, true); + if (obedit->pose != NULL) { + BKE_pose_channels_clear_with_null_bone(obedit->pose, true); + } } } /* TODO(sergey): Pose channels might have been changed, so need -- cgit v1.2.3