From 70269115028752090d40bdd0f36c1e868c9cb4e4 Mon Sep 17 00:00:00 2001 From: Falk David Date: Mon, 13 Oct 2025 17:33:08 +0200 Subject: [PATCH] Fix: Core: Crash when trying to link shapekey from driver target Found while trying to append the scene from this file: https://studio.blender.org/characters/rain/showcase/1/ Before calling `id_lib_extern` when setting the id in the driver target, check that the ID is linkable. Pull Request: https://projects.blender.org/blender/blender/pulls/147829 --- source/blender/makesrna/intern/rna_fcurve.cc | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/source/blender/makesrna/intern/rna_fcurve.cc b/source/blender/makesrna/intern/rna_fcurve.cc index 2d952cf8196..e8e3d559297 100644 --- a/source/blender/makesrna/intern/rna_fcurve.cc +++ b/source/blender/makesrna/intern/rna_fcurve.cc @@ -191,6 +191,8 @@ static const EnumPropertyItem rna_enum_driver_target_context_property_items[] = # include "BKE_anim_data.hh" # include "BKE_fcurve.hh" # include "BKE_fcurve_driver.h" +# include "BKE_idtype.hh" +# include "BKE_lib_id.hh" # include "BKE_report.hh" # include "DEG_depsgraph.hh" @@ -351,6 +353,27 @@ static void rna_DriverVariable_update_data(Main *bmain, Scene *scene, PointerRNA /* ----------- */ +void rna_DriverTarget_id_set(PointerRNA *ptr, PointerRNA value, struct ReportList * /*reports*/) +{ + DriverTarget *data = ptr->data_as(); + ID *id = value.data_as(); + if (!id) { + data->id = nullptr; + return; + } + BLI_assert(id == value.owner_id); + if (ptr->owner_id && !BKE_id_can_use_id(*ptr->owner_id, *id)) { + return; + } + /* Driver targets may be local data referencing unlinkable data like shape keys. These cannot be + * directly linked. + * FIXME: Band-aid, find a better way to handle this. */ + if (BKE_idtype_idcode_is_linkable(GS(id->name))) { + id_lib_extern(id); + } + data->id = id; +} + static StructRNA *rna_DriverTarget_id_typef(PointerRNA *ptr) { DriverTarget *dtar = (DriverTarget *)ptr->data; @@ -1972,7 +1995,8 @@ static void rna_def_drivertarget(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ID_REFCOUNT); RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); RNA_def_property_editable_func(prop, "rna_DriverTarget_id_editable"); - RNA_def_property_pointer_funcs(prop, nullptr, nullptr, "rna_DriverTarget_id_typef", nullptr); + RNA_def_property_pointer_funcs( + prop, nullptr, "rna_DriverTarget_id_set", "rna_DriverTarget_id_typef", nullptr); RNA_def_property_ui_text(prop, "ID", "ID-block that the specific property used can be found from "