From aa50de76a7a7dd6a0697ce2f16274923f00cd04e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 1 Aug 2025 18:17:08 +0200 Subject: [PATCH] Fix assert when assigning active material of an object through RNA. This is yet another fully virtual property (it does not exist as-is in DNA, and requires both getter and setter) that does handle ID refcounting of the affected materials. Now these require an explicit definition of `PROP_ID_REFCOUNT`, as this flag cannot be defined automatically by makesrna. --- source/blender/makesrna/RNA_types.hh | 10 ++++++---- source/blender/makesrna/intern/rna_object.cc | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/blender/makesrna/RNA_types.hh b/source/blender/makesrna/RNA_types.hh index be536e1bf31..21b05d8645f 100644 --- a/source/blender/makesrna/RNA_types.hh +++ b/source/blender/makesrna/RNA_types.hh @@ -337,13 +337,15 @@ enum PropertyFlag { /* pointers */ /** - * Automatically update the ID user count when the property changes value. + * Mark this property as handling ID user count. * - * This is done in the auto-generated setter function. If an RNA property has a custom setter, - * this flag is ignored, and the setter is responsible for correctly updating the user count. + * This is done automatically by the auto-generated setter function. If an RNA property has a + * custom setter, it's the setter's responsibility to correctly update the user count. * * \note In most basic cases, makesrna will automatically set this flag, based on the - * `STRUCT_ID_REFCOUNT` flag of the defined pointer type. + * `STRUCT_ID_REFCOUNT` flag of the defined pointer type. This only works if makesrna can find a + * matching DNA property though, 'virtual' RNA properties (using both a getter and setter) will + * never get this flag defined automatically. */ PROP_ID_REFCOUNT = (1 << 6), diff --git a/source/blender/makesrna/intern/rna_object.cc b/source/blender/makesrna/intern/rna_object.cc index d5b4ac0142f..2feffe05da9 100644 --- a/source/blender/makesrna/intern/rna_object.cc +++ b/source/blender/makesrna/intern/rna_object.cc @@ -3018,7 +3018,7 @@ static void rna_def_object(BlenderRNA *brna) "rna_Object_active_material_set", nullptr, "rna_MaterialSlot_material_poll"); - RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); RNA_def_property_editable_func(prop, "rna_Object_active_material_editable"); RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_MaterialSlot_update");