Fix T59248: Crash in Grease Pencil Edit mode when adding Annotation
authorAntonioya <blendergit@gmail.com>
Wed, 12 Dec 2018 18:48:24 +0000 (19:48 +0100)
committerAntonioya <blendergit@gmail.com>
Wed, 12 Dec 2018 18:48:24 +0000 (19:48 +0100)
source/blender/draw/engines/gpencil/gpencil_draw_utils.c
source/blender/draw/engines/gpencil/gpencil_engine.c

index fe950d2..2450f94 100644 (file)
@@ -1387,28 +1387,32 @@ static void DRW_gpencil_shgroups_create(
                        }
                        case eGpencilBatchGroupType_Edit:
                        {
-                               const int len = elm->vertex_idx - start_edit;
-                               /* use always the same group */
-                               DRW_shgroup_call_range_add(
-                                       stl->g_data->shgrps_edit_point,
-                                       cache->b_edit.batch,
-                                       (!cache_ob->is_dup_ob) ? gpf->runtime.viewmatrix : cache_ob->obmat,
-                                       start_edit, len);
-
-                               start_edit = elm->vertex_idx;
+                               if (stl->g_data->shgrps_edit_point) {
+                                       const int len = elm->vertex_idx - start_edit;
+                                       /* use always the same group */
+                                       DRW_shgroup_call_range_add(
+                                               stl->g_data->shgrps_edit_point,
+                                               cache->b_edit.batch,
+                                               (!cache_ob->is_dup_ob) ? gpf->runtime.viewmatrix : cache_ob->obmat,
+                                               start_edit, len);
+
+                                       start_edit = elm->vertex_idx;
+                               }
                                break;
                        }
                        case eGpencilBatchGroupType_Edlin:
                        {
-                               const int len = elm->vertex_idx - start_edlin;
-                               /* use always the same group */
-                               DRW_shgroup_call_range_add(
-                                       stl->g_data->shgrps_edit_line,
-                                       cache->b_edlin.batch,
-                                       (!cache_ob->is_dup_ob) ? gpf->runtime.viewmatrix : cache_ob->obmat,
-                                       start_edlin, len);
-
-                               start_edlin = elm->vertex_idx;
+                               if (stl->g_data->shgrps_edit_line) {
+                                       const int len = elm->vertex_idx - start_edlin;
+                                       /* use always the same group */
+                                       DRW_shgroup_call_range_add(
+                                               stl->g_data->shgrps_edit_line,
+                                               cache->b_edlin.batch,
+                                               (!cache_ob->is_dup_ob) ? gpf->runtime.viewmatrix : cache_ob->obmat,
+                                               start_edlin, len);
+
+                                       start_edlin = elm->vertex_idx;
+                               }
                                break;
                        }
                        default:
index 483d6a8..11bb5c7 100644 (file)
@@ -719,6 +719,8 @@ void GPENCIL_draw_scene(void *ved)
        Object *obact = draw_ctx->obact;
        const bool playing = stl->storage->is_playing;
        const bool is_render = stl->storage->is_render;
+       bGPdata *gpd_act = (obact) && (obact->type == OB_GPENCIL) ? (bGPdata *)obact->data : NULL;
+       const bool is_edit = GPENCIL_ANY_EDIT_MODE(gpd_act);
 
        /* paper pass to display a comfortable area to draw over complex scenes with geometry */
        if ((!is_render) && (obact) && (obact->type == OB_GPENCIL)) {
@@ -875,7 +877,7 @@ void GPENCIL_draw_scene(void *ved)
                                }
                        }
                        /* edit points */
-                       if ((!is_render) && (!playing)) {
+                       if ((!is_render) && (!playing) && (is_edit)) {
                                DRW_draw_pass(psl->edit_pass);
                        }
                }