From 6c045f73354bd7b99fcd5f0996c3c9fbfebe40dc Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 12 Apr 2024 17:35:22 +0200 Subject: [PATCH] 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 --- source/blender/makesrna/intern/rna_object.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/blender/makesrna/intern/rna_object.cc b/source/blender/makesrna/intern/rna_object.cc index 2cd77bfb55e..a382b4a0024 100644 --- a/source/blender/makesrna/intern/rna_object.cc +++ b/source/blender/makesrna/intern/rna_object.cc @@ -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(ptr->owner_id); + + value = std::max(std::min(value, ob->totcol - 1), 0); ob->actcol = value + 1; if (ob->type == OB_MESH) {