From 67b0e05a624bc6600bbc041d61c778c0cf344ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 17 Jun 2025 22:42:43 +0200 Subject: [PATCH] Fix #139762: Deleting an F-Curve from NLA strip in tweak mode crashes The "delete this F-Curve" function assumes that the F-Curve is either a driver or contained in `adt->action`. This does not have to be true, as the Action editor can also show F-Curves from other uses (for example an NLA strip). The channel delete operator (`ANIM_OT_channels_delete`) now takes this into account. Pull Request: https://projects.blender.org/blender/blender/pulls/140291 --- source/blender/animrig/ANIM_animdata.hh | 2 ++ .../editors/animation/anim_channels_edit.cc | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/blender/animrig/ANIM_animdata.hh b/source/blender/animrig/ANIM_animdata.hh index 59005f230dd..4cd4ee2ed14 100644 --- a/source/blender/animrig/ANIM_animdata.hh +++ b/source/blender/animrig/ANIM_animdata.hh @@ -33,6 +33,8 @@ bAction *id_action_ensure(Main *bmain, ID *id); /** * Delete the F-Curve from the given AnimData block (if possible), * as appropriate according to animation context. + * + * \note This function cannot be used to delete F-Curves from an NLA strip's Action. */ void animdata_fcurve_delete(AnimData *adt, FCurve *fcu); diff --git a/source/blender/editors/animation/anim_channels_edit.cc b/source/blender/editors/animation/anim_channels_edit.cc index a3b3e090efa..d3de3d24ce0 100644 --- a/source/blender/editors/animation/anim_channels_edit.cc +++ b/source/blender/editors/animation/anim_channels_edit.cc @@ -2941,7 +2941,22 @@ static wmOperatorStatus animchannels_delete_exec(bContext *C, wmOperator * /*op* /* try to free F-Curve */ BLI_assert_msg((fcu->driver != nullptr) == (ac.datatype == ANIMCONT_DRIVERS), "Expecting only driver F-Curves in the drivers editor"); - blender::animrig::animdata_fcurve_delete(adt, fcu); + if (ale->fcurve_owner_id && GS(ale->fcurve_owner_id->name) == ID_AC) { + /* F-Curves can be owned by Actions assigned to NLA strips, which + * `animrig::animdata_fcurve_delete()` (below) cannot handle. */ + BLI_assert_msg(!fcu->driver, "Drivers are not expected to be owned by Actions"); + blender::animrig::Action &action = + reinterpret_cast(ale->fcurve_owner_id)->wrap(); + BLI_assert(!action.is_action_legacy()); + action_fcurve_remove(action, *fcu); + } + else if (fcu->driver || adt->action) { + /* This function only works for drivers & directly-assigned Actions: */ + blender::animrig::animdata_fcurve_delete(adt, fcu); + } + else { + BLI_assert_unreachable(); + } tag_update_animation_element(ale); break; }