Merging r39191 through r39250 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / gpencil / gpencil_paint.c
index 81715ea116e59eb38d1170b28708f4e51853eb18..53a17efe88deab058bf17c1ad2d2334983803e5f 100644 (file)
@@ -1749,13 +1749,18 @@ static int gpencil_draw_modal (bContext *C, wmOperator *op, wmEvent *event)
                /* standard undo/redo shouldn't be allowed to execute or else it causes crashes, so catch it here */
                // FIXME: this is a hardcoded hotkey that can't be changed
                // TODO: catch redo as well, but how?
-               if (event->type == ZKEY) {
+               if (event->type == ZKEY && event->val == KM_RELEASE) {
                        /* oskey = cmd key on macs as they seem to use cmd-z for undo as well? */
                        if ((event->ctrl) || (event->oskey)) {
                                /* just delete last stroke, which will look like undo to the end user */
                                //printf("caught attempted undo event... deleting last stroke \n");
                                gpencil_frame_delete_laststroke(p->gpl, p->gpf);
-                               
+                               /* undoing the last line can free p->gpf
+                                * note, could do this in a bit more of an elegant way then a search but it at least prevents a crash */
+                               if(BLI_findindex(&p->gpl->frames, p->gpf) == -1) {
+                                       p->gpf= NULL;
+                               }
+
                                /* event handled, so force refresh */
                                ED_region_tag_redraw(p->ar); /* just active area for now, since doing whole screen is too slow */
                                estate = OPERATOR_RUNNING_MODAL;