Fix #114428: clamp setting object active_material_index #120434

Merged
Philipp Oeser merged 4 commits from lichtwerk/blender:114428 into main 2024-04-12 17:35:33 +02:00

4 Commits

Author SHA1 Message Date
Philipp Oeser 33d0b13541 yet another version of the clamp (same behavior) 2024-04-12 16:11:57 +02:00
Philipp Oeser ada28acd31 refine the clamp
ensure we dont get negative value in case no materials are present to
begin with
2024-04-10 10:57:25 +02:00
Philipp Oeser 0a30ee48a8 address review
- use std::clamp
-- however, we should clamp to ob->totcol -1, no?
- fix mistake (mat_nr is zero-based and actcol is 1 based)
2024-04-10 10:09:16 +02:00
Philipp Oeser d8bfde928b 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`)
2024-04-09 16:25:13 +02:00