Fix #114428: clamp setting object active_material_index
There were multiple reports with objects having many empty material slots. The underlying reason for this is the behavior of adding/assigning materials [which makes room in the form of empty material slots based on the current `active_material_index` -- which atm. can be set to arbitrary values]. So just e.g. setting this to 100 in a fresh file and assigning a material would create 99 empty slots. To resolve, now clamp to the existing number of material slots. NOTE: there is already a range function defined, but this actually only kicks in from the animation system (so clamping would take place there), so clamping is expected to happen in the set functions (there is also a related comment in `RNA_property_int_set`) Pull Request: https://projects.blender.org/blender/blender/pulls/120434
This commit is contained in:
committed by
Philipp Oeser
parent
2361f90264
commit
6c045f7335
@@ -1120,6 +1120,8 @@ static int rna_Object_active_material_index_get(PointerRNA *ptr)
|
||||
static void rna_Object_active_material_index_set(PointerRNA *ptr, int value)
|
||||
{
|
||||
Object *ob = reinterpret_cast<Object *>(ptr->owner_id);
|
||||
|
||||
value = std::max(std::min(value, ob->totcol - 1), 0);
|
||||
ob->actcol = value + 1;
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
|
||||
Reference in New Issue
Block a user