Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-11-11 04:14:48 +0300
committerHans Goudey <h.goudey@me.com>2022-11-11 04:41:13 +0300
commit9465b109af0b70244a36f9e68493e316d9f8b56f (patch)
treec4d933bf09f8313071556063156538ec3356b24c /source/blender/render/intern/bake.c
parent026d21a225521670c6b5083da9da61227da69e65 (diff)
parentca1642cd0c5cdf634fe2022c955d93983de95934 (diff)
Merge branch 'master' into refactor-mesh-position-genericrefactor-mesh-position-generic
Diffstat (limited to 'source/blender/render/intern/bake.c')
-rw-r--r--source/blender/render/intern/bake.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/source/blender/render/intern/bake.c b/source/blender/render/intern/bake.c
index 74a4dfdf6d9..8e413d3b80a 100644
--- a/source/blender/render/intern/bake.c
+++ b/source/blender/render/intern/bake.c
@@ -747,6 +747,7 @@ void RE_bake_pixels_populate(Mesh *me,
BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
const int *material_indices = BKE_mesh_material_indices(me);
+ const int materials_num = targets->materials_num;
for (int i = 0; i < tottri; i++) {
const MLoopTri *lt = &looptri[i];
@@ -754,7 +755,10 @@ void RE_bake_pixels_populate(Mesh *me,
bd.primitive_id = i;
/* Find images matching this material. */
- Image *image = targets->material_to_image[material_indices ? material_indices[lt->poly] : 0];
+ const int material_index = (material_indices && materials_num) ?
+ clamp_i(material_indices[lt->poly], 0, materials_num - 1) :
+ 0;
+ Image *image = targets->material_to_image[material_index];
for (int image_id = 0; image_id < targets->images_num; image_id++) {
BakeImage *bk_image = &targets->images[image_id];
if (bk_image->image != image) {