GPencil: Fix segment fault when undo
authorAntonioya <blendergit@gmail.com>
Mon, 29 Aug 2016 20:17:57 +0000 (22:17 +0200)
committerAntonioya <blendergit@gmail.com>
Mon, 29 Aug 2016 20:17:57 +0000 (22:17 +0200)
When undo in UV/Image editor and press ESC key, there was segment fault
in Toolsettings because the reference was missing. Now the toolsetting
is loaded from context and not from local operator data.

source/blender/editors/gpencil/gpencil_paint.c

index 70a4b2904ed4c53523781bd86cdf11e33cb659a6..cc45cbd82af15fb853dc1b4f578d853586e7577b 100644 (file)
@@ -2310,6 +2310,7 @@ static void gpencil_move_last_stroke_to_back(bContext *C)
 static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
        tGPsdata *p = op->customdata;
+       ToolSettings *ts = CTX_data_tool_settings(C);
        int estate = OPERATOR_PASS_THROUGH; /* default exit state - pass through to support MMB view nav, etc. */
        
        /* if (event->type == NDOF_MOTION)
@@ -2363,9 +2364,11 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
                /* exit() ends the current stroke before cleaning up */
                /* printf("\t\tGP - end of paint op + end of stroke\n"); */
                /* if drawing polygon and enable on back, must move stroke */
-               if ((p->scene->toolsettings->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode == GP_PAINTMODE_DRAW_POLY)) {
-                       if (p->flags & GP_PAINTFLAG_STROKEADDED) {
-                               gpencil_move_last_stroke_to_back(C);
+               if (ts) {
+                       if ((ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode == GP_PAINTMODE_DRAW_POLY)) {
+                               if (p->flags & GP_PAINTFLAG_STROKEADDED) {
+                                       gpencil_move_last_stroke_to_back(C);
+                               }
                        }
                }
                p->status = GP_STATUS_DONE;
@@ -2425,9 +2428,11 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
                        else {
                                /* printf("\t\tGP - end of stroke + op\n"); */
                                /* if drawing polygon and enable on back, must move stroke */
-                               if ((p->scene->toolsettings->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode == GP_PAINTMODE_DRAW_POLY)) {
-                                       if (p->flags & GP_PAINTFLAG_STROKEADDED) {
-                                               gpencil_move_last_stroke_to_back(C);
+                               if (ts) {
+                                       if ((ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode == GP_PAINTMODE_DRAW_POLY)) {
+                                               if (p->flags & GP_PAINTFLAG_STROKEADDED) {
+                                                       gpencil_move_last_stroke_to_back(C);
+                                               }
                                        }
                                }
                                p->status = GP_STATUS_DONE;
@@ -2511,9 +2516,11 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
                                 *       region (as above)
                                 */
                                /* if drawing polygon and enable on back, must move stroke */
-                               if ((p->scene->toolsettings->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode == GP_PAINTMODE_DRAW_POLY)) {
-                                       if (p->flags & GP_PAINTFLAG_STROKEADDED) {
-                                               gpencil_move_last_stroke_to_back(C);
+                               if (ts) {
+                                       if ((ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode == GP_PAINTMODE_DRAW_POLY)) {
+                                               if (p->flags & GP_PAINTFLAG_STROKEADDED) {
+                                                       gpencil_move_last_stroke_to_back(C);
+                                               }
                                        }
                                }
                                p->status = GP_STATUS_DONE;