[Bf-blender-cvs] [0c3219ac940] greasepencil-object: GPencil: Fix segment fault using Reset All

Antonio Vazquez noreply at git.blender.org
Wed Nov 27 19:57:21 CET 2019


Commit: 0c3219ac9409847039d54928dcb510533099ae69
Author: Antonio Vazquez
Date:   Wed Nov 27 19:57:14 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB0c3219ac9409847039d54928dcb510533099ae69

GPencil: Fix segment fault using Reset All

The tool was null and need to be sure the toolslot is right.

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

M	source/blender/blenkernel/intern/brush.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/makesdna/DNA_brush_types.h

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

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 5d13d4d154a..5d9853f268d 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -288,6 +288,7 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
 
   /* Set preset type. */
   brush->gpencil_settings->preset_type = type;
+  brush->gpencil_settings->flag &= ~GP_BRUSH_TAG;
 
   /* Set vertex mix factor. */
   brush->gpencil_settings->vertex_mode = GPPAINT_MODE_STROKE;
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index fea9e743b5b..3dd9104f013 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1634,7 +1634,7 @@ void GPENCIL_OT_brush_reset(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static void gp_bruh_delete_mode_brushes(Main *bmain, const enum eContextObjectMode mode)
+static void gp_bruh_tag_mode_brushes(Main *bmain, const enum eContextObjectMode mode)
 {
   Brush *brush_next = NULL;
   for (Brush *brush = bmain->brushes.first; brush; brush = brush_next) {
@@ -1649,10 +1649,12 @@ static void gp_bruh_delete_mode_brushes(Main *bmain, const enum eContextObjectMo
 
     if (preset != GP_BRUSH_PRESET_UNKNOWN) {
       /* Verify to delete only the brushes of the current mode. */
-      if ((mode == CTX_MODE_PAINT_GPENCIL) &&
-          ((preset < GP_BRUSH_PRESET_AIRBRUSH) || (preset > GP_BRUSH_PRESET_TINT))) {
-        continue;
+      if (mode == CTX_MODE_PAINT_GPENCIL) {
+        if ((preset < GP_BRUSH_PRESET_AIRBRUSH) || (preset > GP_BRUSH_PRESET_TINT)) {
+          continue;
+        }
       }
+
       if ((mode == CTX_MODE_SCULPT_GPENCIL) &&
           ((preset < GP_BRUSH_PRESET_SMOOTH_STROKE) || (preset > GP_BRUSH_PRESET_CLONE_STROKE))) {
         continue;
@@ -1666,6 +1668,20 @@ static void gp_bruh_delete_mode_brushes(Main *bmain, const enum eContextObjectMo
       }
     }
 
+    brush->gpencil_settings->flag |= GP_BRUSH_TAG;
+  }
+}
+
+static void gp_bruh_delete_tagged_brushes(Main *bmain, const enum eContextObjectMode mode)
+{
+  Brush *brush_next = NULL;
+  for (Brush *brush = bmain->brushes.first; brush; brush = brush_next) {
+    brush_next = brush->id.next;
+
+    if ((brush->gpencil_settings == NULL) ||
+        ((brush->gpencil_settings->flag & GP_BRUSH_TAG) == 0)) {
+      continue;
+    }
     /* Before delete, unpinn any material of the brush. */
     if ((brush->gpencil_settings) && (brush->gpencil_settings->material != NULL)) {
       brush->gpencil_settings->material = NULL;
@@ -1685,26 +1701,34 @@ static int gp_brush_reset_all_exec(bContext *C, wmOperator *UNUSED(op))
 
   switch (mode) {
     case CTX_MODE_PAINT_GPENCIL: {
-      gp_bruh_delete_mode_brushes(bmain, mode);
+      gp_bruh_tag_mode_brushes(bmain, mode);
       BKE_brush_gpencil_paint_presets(bmain, ts);
+      gp_bruh_delete_tagged_brushes(bmain, mode);
+      BKE_paint_toolslots_brush_validate(bmain, &ts->gp_paint->paint);
       changed = true;
       break;
     }
     case CTX_MODE_SCULPT_GPENCIL: {
-      gp_bruh_delete_mode_brushes(bmain, mode);
+      gp_bruh_tag_mode_brushes(bmain, mode);
       BKE_brush_gpencil_sculpt_presets(bmain, ts);
+      gp_bruh_delete_tagged_brushes(bmain, mode);
+      BKE_paint_toolslots_brush_validate(bmain, &ts->gp_sculptpaint->paint);
       changed = true;
       break;
     }
     case CTX_MODE_WEIGHT_GPENCIL: {
-      gp_bruh_delete_mode_brushes(bmain, mode);
+      gp_bruh_tag_mode_brushes(bmain, mode);
       BKE_brush_gpencil_weight_presets(bmain, ts);
+      gp_bruh_delete_tagged_brushes(bmain, mode);
+      BKE_paint_toolslots_brush_validate(bmain, &ts->gp_weightpaint->paint);
       changed = true;
       break;
     }
     case CTX_MODE_VERTEX_GPENCIL: {
-      gp_bruh_delete_mode_brushes(bmain, mode);
+      gp_bruh_tag_mode_brushes(bmain, mode);
       BKE_brush_gpencil_vertex_presets(bmain, ts);
+      gp_bruh_delete_tagged_brushes(bmain, mode);
+      BKE_paint_toolslots_brush_validate(bmain, &ts->gp_vertexpaint->paint);
       changed = true;
       break;
     }
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index c2be0a98dbb..7a34b63969b 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -182,6 +182,8 @@ typedef enum eGPDbrush_Flag {
   GP_BRUSH_USE_STENGTH_PRESSURE = (1 << 1),
   /* brush use pressure for alpha factor */
   GP_BRUSH_USE_JITTER_PRESSURE = (1 << 2),
+  /* brush tagged to delete. */
+  GP_BRUSH_TAG = (1 << 3),
   /* fill hide transparent */
   GP_BRUSH_FILL_HIDE = (1 << 6),
   /* show fill help lines */



More information about the Bf-blender-cvs mailing list