Fix #114428: clamp setting object active_material_index #120434
|
@ -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);
|
||||
Campbell Barton
commented
There may be no materials which will assert, suggest
There may be no materials which will assert, suggest
`value = (ob->totcol > 1) ? std::clamp(value, 0, ob->totcol - 1) : 0;`
Hans Goudey
commented
`std::max(std::min(value, ob->totcol - 1), 0);` might be even simpler
|
||||
ob->actcol = value + 1;
|
||||
Hans Goudey
commented
`std::clamp(value, 0, ob->totcol)` seems simpler here
Philipp Oeser
commented
we should really clamp to > `std::clamp(value, 0, ob->totcol)` seems simpler here
we should really clamp to `ob->totcol -1` here then, no?
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
|
|
Loading…
Reference in New Issue
There is an error in the code introduced as
mat_nr
is zero-based andactcol
is 1 based, so the assignment should bemat_nr = ob->actcol - 1
however I think it's better to clamp value once at the beginning of the function.