[Bf-blender-cvs] [be1f4d875fb] master: Fix T72013: Gpencil Interpolate strokes causes instant crash when material list is empty

Antonio Vazquez noreply at git.blender.org
Fri Nov 29 11:25:19 CET 2019


Commit: be1f4d875fb8001a10886a8577032e0f197827d3
Author: Antonio Vazquez
Date:   Fri Nov 29 11:22:36 2019 +0100
Branches: master
https://developer.blender.org/rBbe1f4d875fb8001a10886a8577032e0f197827d3

Fix T72013: Gpencil Interpolate strokes causes instant crash when material list is empty

The problem was the draw function tried to use the material and gpsettings and both were NULL.

Now, the default material is used.

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

M	source/blender/blenkernel/BKE_material.h
M	source/blender/blenkernel/intern/material.c
M	source/blender/editors/gpencil/drawgpencil.c

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

diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 7ff9c4e6376..d7b037a8189 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -95,6 +95,7 @@ bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob);
 bool BKE_object_material_slot_used(struct ID *id, short actcol);
 
 struct Material *BKE_material_gpencil_get(struct Object *ob, short act);
+struct Material *BKE_material_gpencil_default_get(void);
 struct MaterialGPencilStyle *BKE_material_gpencil_settings_get(struct Object *ob, short act);
 
 void BKE_texpaint_slot_refresh_cache(struct Scene *scene, struct Material *ma);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 73c278a0ab6..54432c8da74 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -598,6 +598,11 @@ Material *BKE_material_gpencil_get(Object *ob, short act)
   }
 }
 
+struct Material *BKE_material_gpencil_default_get(void)
+{
+  return &defgpencil_material;
+}
+
 MaterialGPencilStyle *BKE_material_gpencil_settings_get(Object *ob, short act)
 {
   Material *ma = give_current_material(ob, act);
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 80795b825b0..06e5f36637b 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -51,6 +51,7 @@
 #include "BKE_context.h"
 #include "BKE_brush.h"
 #include "BKE_global.h"
+#include "BKE_material.h"
 #include "BKE_paint.h"
 #include "BKE_gpencil.h"
 #include "BKE_image.h"
@@ -427,7 +428,9 @@ static void gp_draw_stroke_fill(bGPdata *gpd,
                                 const float color[4])
 {
   BLI_assert(gps->totpoints >= 3);
-  Material *ma = gpd->mat[gps->mat_nr];
+  const bool use_mat = (gpd->mat != NULL);
+
+  Material *ma = (use_mat) ? gpd->mat[gps->mat_nr] : BKE_material_gpencil_default_get();
   MaterialGPencilStyle *gp_style = (ma) ? ma->gp_style : NULL;
 
   /* Calculate triangles cache for filling area (must be done only after changes) */
@@ -869,6 +872,7 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
   short sthickness;
   float ink[4];
   const bool is_unique = (tgpw->gps != NULL);
+  const bool use_mat = (tgpw->gpd->mat != NULL);
 
   GPU_program_point_size(true);
 
@@ -880,7 +884,7 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
       continue;
     }
     /* check if the color is visible */
-    Material *ma = tgpw->gpd->mat[gps->mat_nr];
+    Material *ma = (use_mat) ? tgpw->gpd->mat[gps->mat_nr] : BKE_material_gpencil_default_get();
     MaterialGPencilStyle *gp_style = (ma) ? ma->gp_style : NULL;
 
     if ((gp_style == NULL) || (gp_style->flag & GP_STYLE_COLOR_HIDE) ||
@@ -1159,6 +1163,9 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in
       copy_v4_v4(tgpw.tintcolor, color);
       tgpw.onion = true;
       tgpw.custonion = true;
+      if (obact->totcol == 0) {
+        tgpw.gpd->mat = NULL;
+      }
 
       gp_draw_strokes(&tgpw);
     }



More information about the Bf-blender-cvs mailing list