[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34292] trunk/blender/source/blender/ editors: Bugfix [#25597] Grease Pencil crash when undoing during a Sketching

Joshua Leung aligorith at gmail.com
Thu Jan 13 07:14:14 CET 2011


Revision: 34292
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34292
Author:   aligorith
Date:     2011-01-13 06:14:14 +0000 (Thu, 13 Jan 2011)
Log Message:
-----------
Bugfix [#25597] Grease Pencil crash when undoing during a Sketching
Session

As the key combination for undo was unhandled by Grease Pencil
operator and allowed to execute, some of the lingering Grease Pencil
data would get corrupted by undo as some flags may still have been
set.

This commit attempts to fix.workaround this problem by catching undo
events, using the internal "delete last stroke" functionality to
emulate undo-like behaviour as expected but without the associated
risks. The underlying functionality used was already part of the
original 2.4 implementation, but was exposed via the GUI instead there
where it was less useful.

---

Other tweaks related to Grease Pencil:
1) Spacebar can be used to end Sketching Sessions too now
2) Grease Pencil animation editor now displays GP datablocks in light
blue (i.e. "sub-id") colours as per dopesheet instead of them being
presented like groups. This better reflects their true nature.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_channels_defines.c
    trunk/blender/source/blender/editors/gpencil/gpencil_paint.c

Modified: trunk/blender/source/blender/editors/animation/anim_channels_defines.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2011-01-13 05:05:10 UTC (rev 34291)
+++ trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2011-01-13 06:14:14 UTC (rev 34292)
@@ -2412,11 +2412,8 @@
 /* get backdrop color for gpencil datablock widget */
 static void acf_gpd_color(bAnimContext *UNUSED(ac), bAnimListElem *UNUSED(ale), float *color)
 {
-	/* highlight only for datablock channels */
-	//if (ale->flag & AGRP_ACTIVE)
-	//	UI_GetThemeColorShade3fv(TH_GROUP_ACTIVE, 10, color);
-	//else
-		UI_GetThemeColorShade3fv(TH_GROUP, 20, color);
+	/* these are ID-blocks, but not exactly standalone... */
+	UI_GetThemeColorShade3fv(TH_DOPESHEET_CHANNELSUBOB, 20, color);
 }
 
 // TODO: just get this from RNA?

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-01-13 05:05:10 UTC (rev 34291)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-01-13 06:14:14 UTC (rev 34292)
@@ -1555,7 +1555,7 @@
 	//printf("\tGP - handle modal event...\n");
 	
 	/* exit painting mode (and/or end current stroke) */
-	if (ELEM3(event->type, RETKEY, PADENTER, ESCKEY)) {
+	if (ELEM4(event->type, RETKEY, PADENTER, ESCKEY, SPACEKEY)) {
 		/* exit() ends the current stroke before cleaning up */
 		//printf("\t\tGP - end of paint op + end of stroke\n");
 		gpencil_draw_exit(C, op);
@@ -1615,24 +1615,43 @@
 		}
 	}
 	
-	/* handle painting mouse-movements? */
-	if ((p->status == GP_STATUS_PAINTING) && 
-		(ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) ) 
-	{
-		/* handle drawing event */
-		//printf("\t\tGP - add point\n");
-		gpencil_draw_apply_event(op, event);
-		
-		/* finish painting operation if anything went wrong just now */
-		if (p->status == GP_STATUS_ERROR) {
-			//printf("\t\t\t\tGP - add error done! \n");
-			gpencil_draw_exit(C, op);
-			estate = OPERATOR_CANCELLED;
+	/* handle mode-specific events */
+	if (p->status == GP_STATUS_PAINTING) {
+		/* handle painting mouse-movements? */
+		if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) 
+		{
+			/* handle drawing event */
+			//printf("\t\tGP - add point\n");
+			gpencil_draw_apply_event(op, event);
+			
+			/* finish painting operation if anything went wrong just now */
+			if (p->status == GP_STATUS_ERROR) {
+				//printf("\t\t\t\tGP - add error done! \n");
+				gpencil_draw_exit(C, op);
+				estate = OPERATOR_CANCELLED;
+			}
+			else {
+				/* event handled, so just tag as running modal */
+				//printf("\t\t\t\tGP - add point handled!\n");
+				estate = OPERATOR_RUNNING_MODAL;
+			}
 		}
-		else {
-			/* event handled, so just tag as running modal */
-			//printf("\t\t\t\tGP - add point handled!\n");
-			estate = OPERATOR_RUNNING_MODAL;
+	}
+	else if (p->status == GP_STATUS_IDLING) {
+		/* 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) {
+			/* 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);
+				
+				/* 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; 
+			}
 		}
 	}
 	




More information about the Bf-blender-cvs mailing list