From 3233ddc3b37476f52be0f59be92076dc700d9368 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 1 Jul 2025 14:28:27 +0200 Subject: [PATCH] Fix #141243: Crash when removing constraints with drivers via python The issue was that the depsgraph was not rebuilt, thus the driver node still stuck around. This then crashed when the depsgraph evaluated. The reason why this wasn't caught in the unit tests, was because the depsgraph was not updated between creating and removing the data. Pull Request: https://projects.blender.org/blender/blender/pulls/141272 --- source/blender/blenkernel/intern/anim_sys.cc | 7 +++++++ source/blender/makesrna/intern/rna_pose.cc | 1 + tests/python/bl_animation_drivers.py | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/source/blender/blenkernel/intern/anim_sys.cc b/source/blender/blenkernel/intern/anim_sys.cc index 345b94f4a47..73eaef3ffa8 100644 --- a/source/blender/blenkernel/intern/anim_sys.cc +++ b/source/blender/blenkernel/intern/anim_sys.cc @@ -4238,6 +4238,13 @@ void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, int driver_index, FCu fcu = static_cast(BLI_findlink(&adt->drivers, driver_index)); } + if (!fcu) { + /* Trying to evaluate a driver that does no longer exist. Potentially missing a call to + * DEG_relations_tag_update. */ + BLI_assert_unreachable(); + return; + } + DEG_debug_print_eval_subdata_index( depsgraph, __func__, id->name, id, "fcu", fcu->rna_path, fcu, fcu->array_index); diff --git a/source/blender/makesrna/intern/rna_pose.cc b/source/blender/makesrna/intern/rna_pose.cc index a58cf6d0bf4..433a88a0f94 100644 --- a/source/blender/makesrna/intern/rna_pose.cc +++ b/source/blender/makesrna/intern/rna_pose.cc @@ -392,6 +392,7 @@ static void rna_PoseChannel_constraints_remove( con_ptr->invalidate(); blender::ed::object::constraint_update(bmain, ob); + DEG_relations_tag_update(bmain); /* XXX(@ideasman42): is this really needed? */ BKE_constraints_active_set(&pchan->constraints, nullptr); diff --git a/tests/python/bl_animation_drivers.py b/tests/python/bl_animation_drivers.py index bcf63d80ddb..6c81a60aa03 100644 --- a/tests/python/bl_animation_drivers.py +++ b/tests/python/bl_animation_drivers.py @@ -236,6 +236,11 @@ class SubDataDriverRemovalTest(AbstractEmptyDriverTest, unittest.TestCase): self.assertEqual(len(pose_bone.constraints), 1) arm_ob.driver_add('pose.bones["test"].constraints["test"].distance') self.assertEqual(len(arm_ob.animation_data.drivers), 1) + + # To do a proper test, the depsgraph needs to be evaluated between adding + # the data and removing it. This causes depsgraph nodes to be built, which + # have to be removed as well. See #141243 + bpy.context.evaluated_depsgraph_get() pose_bone.constraints.remove(constraint) self.assertEqual(len(pose_bone.constraints), 0) self.assertEqual(len(arm_ob.animation_data.drivers), 0,