[Bf-blender-cvs] [bb165d6df10] master: Fix T66957: GPencil material isolate crash when slot is empty

Antonioya noreply at git.blender.org
Mon Jul 15 09:53:33 CEST 2019


Commit: bb165d6df10dcee953b55a52e169e5b9e6bac78e
Author: Antonioya
Date:   Mon Jul 15 09:52:14 2019 +0200
Branches: master
https://developer.blender.org/rBbb165d6df10dcee953b55a52e169e5b9e6bac78e

Fix T66957: GPencil material isolate crash when slot is empty

When the slot of the material is empty, the loop to lock the materials tried to use the material but this was NULL.

Check if material is NULL before using it in other operators too.

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

M	source/blender/editors/gpencil/gpencil_data.c

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

diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 941c7645dc0..90a2b2d613c 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1521,8 +1521,10 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
   /* first lock all colors */
   for (short i = 0; i < *totcol; i++) {
     Material *tmp_ma = give_current_material(ob, i + 1);
-    tmp_ma->gp_style->flag |= GP_STYLE_COLOR_LOCKED;
-    DEG_id_tag_update(&tmp_ma->id, ID_RECALC_COPY_ON_WRITE);
+    if (tmp_ma) {
+      tmp_ma->gp_style->flag |= GP_STYLE_COLOR_LOCKED;
+      DEG_id_tag_update(&tmp_ma->id, ID_RECALC_COPY_ON_WRITE);
+    }
   }
 
   /* loop all selected strokes and unlock any color */
@@ -2433,10 +2435,12 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
 
   for (short i = 0; i < *totcol; i++) {
     ma = give_current_material(ob, i + 1);
-    gp_style = ma->gp_style;
-    gp_style->flag |= GP_STYLE_COLOR_LOCKED;
-    gp_style->flag |= GP_STYLE_COLOR_HIDE;
-    DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    if (ma) {
+      gp_style = ma->gp_style;
+      gp_style->flag |= GP_STYLE_COLOR_LOCKED;
+      gp_style->flag |= GP_STYLE_COLOR_HIDE;
+      DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    }
   }
 
   /* loop all selected strokes and unlock any color used in active layer */
@@ -2515,7 +2519,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
   for (short i = 0; i < *totcol; i++) {
     ma = give_current_material(ob, i + 1);
     /* Skip if this is the active one */
-    if (ma == active_ma) {
+    if ((ma == NULL) || (ma == active_ma)) {
       continue;
     }
 
@@ -2534,6 +2538,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
     /* Set flags on all "other" colors */
     for (short i = 0; i < *totcol; i++) {
       ma = give_current_material(ob, i + 1);
+      if (ma == NULL) {
+        continue;
+      }
       gp_style = ma->gp_style;
       if (gp_style == active_color) {
         continue;
@@ -2548,6 +2555,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
     /* Clear flags - Restore everything else */
     for (short i = 0; i < *totcol; i++) {
       ma = give_current_material(ob, i + 1);
+      if (ma == NULL) {
+        continue;
+      }
       gp_style = ma->gp_style;
       gp_style->flag &= ~flags;
       DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
@@ -2610,10 +2620,12 @@ static int gpencil_color_hide_exec(bContext *C, wmOperator *op)
     MaterialGPencilStyle *color = NULL;
     for (short i = 0; i < *totcol; i++) {
       ma = give_current_material(ob, i + 1);
-      color = ma->gp_style;
-      if (active_color != color) {
-        color->flag |= GP_STYLE_COLOR_HIDE;
-        DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+      if (ma) {
+        color = ma->gp_style;
+        if (active_color != color) {
+          color->flag |= GP_STYLE_COLOR_HIDE;
+          DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+        }
       }
     }
   }
@@ -2671,9 +2683,11 @@ static int gpencil_color_reveal_exec(bContext *C, wmOperator *UNUSED(op))
 
   for (short i = 0; i < *totcol; i++) {
     ma = give_current_material(ob, i + 1);
-    gp_style = ma->gp_style;
-    gp_style->flag &= ~GP_STYLE_COLOR_HIDE;
-    DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    if (ma) {
+      gp_style = ma->gp_style;
+      gp_style->flag &= ~GP_STYLE_COLOR_HIDE;
+      DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    }
   }
 
   /* updates */
@@ -2722,9 +2736,11 @@ static int gpencil_color_lock_all_exec(bContext *C, wmOperator *UNUSED(op))
 
   for (short i = 0; i < *totcol; i++) {
     ma = give_current_material(ob, i + 1);
-    gp_style = ma->gp_style;
-    gp_style->flag |= GP_STYLE_COLOR_LOCKED;
-    DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    if (ma) {
+      gp_style = ma->gp_style;
+      gp_style->flag |= GP_STYLE_COLOR_LOCKED;
+      DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    }
   }
 
   /* updates */
@@ -2773,9 +2789,11 @@ static int gpencil_color_unlock_all_exec(bContext *C, wmOperator *UNUSED(op))
 
   for (short i = 0; i < *totcol; i++) {
     ma = give_current_material(ob, i + 1);
-    gp_style = ma->gp_style;
-    gp_style->flag &= ~GP_STYLE_COLOR_LOCKED;
-    DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    if (ma) {
+      gp_style = ma->gp_style;
+      gp_style->flag &= ~GP_STYLE_COLOR_LOCKED;
+      DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE);
+    }
   }
 
   /* updates */



More information about the Bf-blender-cvs mailing list