[Bf-blender-cvs] [4f2c19b4238] greasepencil-refactor: GPencil: Refactor: Fix crash when drawing on blank gpobject

Clément Foucault noreply at git.blender.org
Fri Jan 10 13:35:55 CET 2020


Commit: 4f2c19b4238f728408a9629848cb60b993305fc6
Author: Clément Foucault
Date:   Fri Jan 10 13:35:41 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB4f2c19b4238f728408a9629848cb60b993305fc6

GPencil: Refactor: Fix crash when drawing on blank gpobject

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

M	source/blender/draw/engines/gpencil/gpencil_draw_data.c
M	source/blender/draw/intern/draw_cache_impl_gpencil.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index b4835543b89..c35244782cf 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -114,7 +114,7 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
   }
 
   GPENCIL_MaterialPool *pool = matpool;
-  for (int i = 0; i < ob->totcol; i++) {
+  for (int i = 0; i < max_ii(1, ob->totcol); i++) {
     int mat_id = (i % GP_MATERIAL_BUFFER_LEN);
     if ((i > 0) && (mat_id == 0)) {
       pool->next = gpencil_material_pool_add(pd);
@@ -145,7 +145,8 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
       }
     }
 
-    if ((gp_style->mode != GP_MATERIAL_MODE_LINE) || (gp_style->flag & GP_MATERIAL_DISABLE_STENCIL)) {
+    if ((gp_style->mode != GP_MATERIAL_MODE_LINE) ||
+        (gp_style->flag & GP_MATERIAL_DISABLE_STENCIL)) {
       mat_data->flag |= GP_STROKE_OVERLAP;
     }
 
diff --git a/source/blender/draw/intern/draw_cache_impl_gpencil.c b/source/blender/draw/intern/draw_cache_impl_gpencil.c
index c687ba75bd5..b574a18cc5d 100644
--- a/source/blender/draw/intern/draw_cache_impl_gpencil.c
+++ b/source/blender/draw/intern/draw_cache_impl_gpencil.c
@@ -501,7 +501,7 @@ bGPDstroke *DRW_cache_gpencil_sbuffer_stroke_data_get(Object *ob)
   if (gpd->runtime.sbuffer_gps == NULL) {
     bGPDstroke *gps = MEM_callocN(sizeof(*gps), "bGPDstroke sbuffer");
     gps->totpoints = gpd->runtime.sbuffer_used;
-    gps->mat_nr = gpd->runtime.matid - 1;
+    gps->mat_nr = max_ii(0, gpd->runtime.matid - 1);
     gps->flag = gpd->runtime.sbuffer_sflag;
     gps->thickness = gpd->runtime.brush_size;
     gps->tot_triangles = max_ii(0, gpd->runtime.sbuffer_used - 2);



More information about the Bf-blender-cvs mailing list