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.
This commit is contained in:
Bastien Montagne
2025-08-01 18:17:08 +02:00
parent 5725176312
commit aa50de76a7
2 changed files with 7 additions and 5 deletions

View File

@@ -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),

View File

@@ -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");