[Bf-blender-cvs] [097b9019cee] master: Fix T59799: texture paint mode crash for object with no materials.

Brecht Van Lommel noreply at git.blender.org
Thu Dec 27 12:22:12 CET 2018


Commit: 097b9019ceea7e0c9ef399b548dc917b8525c02e
Author: Brecht Van Lommel
Date:   Thu Dec 27 12:18:37 2018 +0100
Branches: master
https://developer.blender.org/rB097b9019ceea7e0c9ef399b548dc917b8525c02e

Fix T59799: texture paint mode crash for object with no materials.

===================================================================

M	source/blender/draw/modes/paint_texture_mode.c

===================================================================

diff --git a/source/blender/draw/modes/paint_texture_mode.c b/source/blender/draw/modes/paint_texture_mode.c
index cf6f32170f1..a89616c2cae 100644
--- a/source/blender/draw/modes/paint_texture_mode.c
+++ b/source/blender/draw/modes/paint_texture_mode.c
@@ -191,12 +191,13 @@ static void PAINT_TEXTURE_cache_init(void *vedata)
 			Scene *scene = draw_ctx->scene;
 			const bool use_material_slots = (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_MATERIAL);
 			const Mesh *me = ob->data;
+			const int mat_nr = max_ii(1, me->totcol);
 
 			stl->g_data->shgroup_image_array = MEM_mallocN(
-			        sizeof(*stl->g_data->shgroup_image_array) * (use_material_slots ? me->totcol : 1), __func__);
+			        sizeof(*stl->g_data->shgroup_image_array) * (use_material_slots ? mat_nr : 1), __func__);
 
 			if (use_material_slots) {
-				for (int i = 0; i < me->totcol; i++) {
+				for (int i = 0; i < mat_nr; i++) {
 					Material *ma = give_current_material(ob, i + 1);
 					Image *ima = (ma && ma->texpaintslot) ? ma->texpaintslot[ma->paint_active_slot].ima : NULL;
 					GPUTexture *tex = ima ?



More information about the Bf-blender-cvs mailing list