Commit: 1871c08160b06dcff924ef723979c46a470992cf
Author: Antony Riakiotakis
Date:   Thu Sep 4 20:23:03 2014 +0200
Branches: master
https://developer.blender.org/rB1871c08160b06dcff924ef723979c46a470992cf

Fix T41716, crash with image mode when painting without materials.

* As always, make sure all slots of the object have a material

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

M       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 8cef74e..2a79b11 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;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to