From 1871c08160b06dcff924ef723979c46a470992cf Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Thu, 4 Sep 2014 20:23:03 +0200 Subject: Fix T41716, crash with image mode when painting without materials. * As always, make sure all slots of the object have a material --- source/blender/editors/sculpt_paint/paint_image.c | 46 ++++++++++++----------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'source/blender/editors/sculpt_paint/paint_image.c') diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 8cef74e9392..2a79b111c6d 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1358,21 +1358,22 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob, wmOperator *op) Main *bmain = CTX_data_main(C); Brush *br = BKE_paint_brush(&imapaint->paint); - if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) { - /* no material, add one */ - if (ob->totcol == 0) { - Material *ma = BKE_material_add(CTX_data_main(C), "Material"); - /* no material found, just assign to first slot */ - assign_material(ob, ma, 1, BKE_MAT_ASSIGN_USERPREF); - proj_paint_add_slot(C, ma, NULL); - } - else { - /* there may be material slots but they may be empty, check */ - int i; - - for (i = 1; i < ob->totcol + 1; i++) { - Material *ma = give_current_material(ob, i); - if (ma) { + /* no material, add one */ + if (ob->totcol == 0) { + Material *ma = BKE_material_add(CTX_data_main(C), "Material"); + /* no material found, just assign to first slot */ + assign_material(ob, ma, 1, BKE_MAT_ASSIGN_USERPREF); + proj_paint_add_slot(C, ma, NULL); + } + else { + /* there may be material slots but they may be empty, check */ + int i; + + for (i = 1; i < ob->totcol + 1; i++) { + Material *ma = give_current_material(ob, i); + + if (ma) { + if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) { if (!ma->texpaintslot) { /* refresh here just in case */ BKE_texpaint_slot_refresh_cache(scene, ma); @@ -1399,16 +1400,17 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob, wmOperator *op) } } } - else { - Material *ma = BKE_material_add(CTX_data_main(C), "Material"); - /* no material found, just assign to first slot */ - assign_material(ob, ma, i, BKE_MAT_ASSIGN_USERPREF); - proj_paint_add_slot(C, ma, NULL); - } + } + else { + Material *ma = BKE_material_add(CTX_data_main(C), "Material"); + /* no material found, just assign to first slot */ + assign_material(ob, ma, i, BKE_MAT_ASSIGN_USERPREF); + proj_paint_add_slot(C, ma, NULL); } } } - else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { + + if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { if (imapaint->canvas == NULL) { int width; int height; -- cgit v1.2.3