From 503866c68154ef09e6199068391515f81eebaa2d Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Thu, 2 Aug 2018 16:34:27 +1200 Subject: Fix T56199: Crash on Annotation in (VSE) Image Preview In some cases (e.g. using old userpref settings/keymaps) it was possible to trigger a crash when the wrong GP/Annotation operators were triggered in the wrong contexts (e.g. using the old GPENCIL_OT_paint in annotation-only contexts like all the 2D editors). This commit resolves several issues that were caused by sloppy code-churn + features that had been hacked on. --- source/blender/editors/gpencil/annotate_paint.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/gpencil/annotate_paint.c') diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index 6325052fccd..b551f3d630b 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -1206,9 +1206,19 @@ static tGPsdata *gp_session_initpaint(bContext *C) /* create new context data */ p = MEM_callocN(sizeof(tGPsdata), "Annotation Drawing Data"); - gp_session_initdata(C, p); + /* Try to initialise context data + * WARNING: This may not always succeed (e.g. using GP in an annotation-only context) + */ + if (gp_session_initdata(C, p) == 0) { + /* Invalid state - Exit + * NOTE: It should be safe to just free the data, since failing context checks should + * only happen when no data has been allocated. + */ + MEM_freeN(p); + return NULL; + } - /* radius for eraser circle is defined in userprefs now */ + /* Radius for eraser circle is defined in userprefs */ /* NOTE: we do this here, so that if we exit immediately, * erase size won't get lost */ @@ -1548,9 +1558,6 @@ static void gpencil_draw_exit(bContext *C, wmOperator *op) { tGPsdata *p = op->customdata; - /* clear undo stack */ - gpencil_undo_finish(); - /* restore cursor to indicate end of drawing */ WM_cursor_modal_restore(CTX_wm_window(C)); @@ -1568,10 +1575,14 @@ static void gpencil_draw_exit(bContext *C, wmOperator *op) */ U.gp_eraser = p->radius; + /* clear undo stack */ + gpencil_undo_finish(); + /* cleanup */ gp_paint_cleanup(p); gp_session_cleanup(p); gp_session_free(p); + p = NULL; } op->customdata = NULL; -- cgit v1.2.3