[Bf-blender-cvs] [4bdba62cb94] master: Fix T94441: fix crash parenting object to a bone

Andrew Oates noreply at git.blender.org
Thu Sep 29 10:35:27 CEST 2022


Commit: 4bdba62cb94978c94d29150d2fd426ca18aa8d0d
Author: Andrew Oates
Date:   Thu Sep 29 10:17:22 2022 +0200
Branches: master
https://developer.blender.org/rB4bdba62cb94978c94d29150d2fd426ca18aa8d0d

Fix T94441: fix crash parenting object to a bone

This crash occurs when the bone is newly created.  In certain
circumstances the depsgraph data for the armature is not updated,
causing `pchan_eval` to be NULL when the parent is updated.  This causes
a segfault in `ED_object_parent_set` when the flags are updated.

This change fixes the underlying depsgraph bug, and also adds both an
assertion and NULL pointer check to `ED_object_parent_set` to better
handle this scenario if it recurs via another path.

Maniphest Tasks: T94441

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

===================================================================

M	source/blender/editors/object/object_relations.c
M	source/blender/makesrna/intern/rna_armature.c

===================================================================

diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 21e56531096..2f18922f4ee 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -570,7 +570,9 @@ bool ED_object_parent_set(ReportList *reports,
       pchan = BKE_pose_channel_active_if_layer_visible(par);
       pchan_eval = BKE_pose_channel_active_if_layer_visible(parent_eval);
 
-      if (pchan == NULL) {
+      if (pchan == NULL || pchan_eval == NULL) {
+        /* If pchan_eval is NULL, pchan should also be NULL. */
+        BLI_assert_msg(pchan == NULL, "Missing evaluated bone data");
         BKE_report(reports, RPT_ERROR, "No active bone");
         return false;
       }
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index f83ec0dc09b..e6b1ea1321c 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -38,6 +38,13 @@
 #  include "DEG_depsgraph.h"
 #  include "DEG_depsgraph_build.h"
 
+static void rna_Armature_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+  ID *id = ptr->owner_id;
+
+  DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
+}
+
 static void rna_Armature_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
   ID *id = ptr->owner_id;
@@ -1365,6 +1372,7 @@ static void rna_def_armature_bones(BlenderRNA *brna, PropertyRNA *cprop)
   RNA_def_property_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop, "Active Bone", "Armature's active bone");
   RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_bone_set", NULL, NULL);
+  RNA_def_property_update(prop, 0, "rna_Armature_update");
 
   /* TODO: redraw. */
   /*      RNA_def_property_collection_active(prop, prop_act); */
@@ -1389,7 +1397,7 @@ static void rna_def_armature_edit_bones(BlenderRNA *brna, PropertyRNA *cprop)
   RNA_def_property_pointer_sdna(prop, NULL, "act_edbone");
   RNA_def_property_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop, "Active EditBone", "Armatures active edit bone");
-  // RNA_def_property_update(prop, 0, "rna_Armature_act_editbone_update");
+  RNA_def_property_update(prop, 0, "rna_Armature_update");
   RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_edit_bone_set", NULL, NULL);
 
   /* TODO: redraw. */



More information about the Bf-blender-cvs mailing list