NSUndoManager grouping problem?

Posted by anonymous on Stack Overflow See other posts from Stack Overflow or by anonymous
Published on 2010-04-01T19:00:20Z Indexed on 2010/04/01 19:03 UTC
Read the original article Hit count: 484

Filed under:
|
|

I'm working on a barebones drawing app. I'm attempting to implement undo/redo capability, so I tell the view's undoManager to save the current image before updating the display. This works perfectly (yes, I understand that redrawing/saving the entire view is not incredibly efficient, but to solve this problem before attempting to optimize the code). However, as expected, when I 'undo' or 'redo', only the minute change is reflected. My goal is to have the whole finger stroke undone/redone. To do that, I told the undoManager to [beginUndoGrouping] in the [touchesBegan] method, and to [endUndoGrouping] in [touchesEnded]. That works for a bit, but after drawing a few strokes, the app crashes, and gdb exits with exc_bad_access.

I'm very grateful for any insight you can give me.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

mouseDragged = YES;

currentPoint = [[touches anyObject] locationInView:self];

UIGraphicsBeginImageContext(drawingImageView.bounds.size);
[drawingImageView.image drawInRect:drawingImageView.bounds];

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, drawingWidth);
[drawingColor setStroke];

CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, previousPoint.x, previousPoint.y);
CGContextAddLineToPoint(ctx, currentPoint.x, currentPoint.y);
CGContextStrokePath(ctx);

[self.undoManager registerUndoWithTarget:drawingImageView selector:@selector(setImage:) object:drawingImageView.image];
drawingImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
previousPoint = currentPoint;

}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about gdb