I am having some problems with an app that keeps crashing intermittently. Code below is in a UIView with CATiledLayer as its backing layer:
- (UIBezierPath *)path
{
if(_path == nil){
_path = [UIBezierPath bezierPath];
CGFloat lineWidth = 5;
[_path setLineWidth:lineWidth];
[_path setLineJoinStyle:kCGLineJoinRound];
[_path setLineCapStyle:kCGLineCapRound];
[_path moveToPoint:CGPointMake(100, 100)];
[_path addLineToPoint:CGPointMake(200,200)];
[_path addLineToPoint:CGPointMake(150,200)];
[_path addLineToPoint:CGPointMake(50,400)];
_path closePath];
return _path;
}
return _path;
}
- (void)drawRect:(CGRect)rect
{
[[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:0.45] setStroke];//sets stroke color in current context
[self.path stroke];
}
I get the following error code:
Single stepping until exit from function _ZN2CG4Path15apply_transformERK17CGAffineTransform, which has no line number information.
There doesn't seem to be any pattern to when the error occurs. It can seems to occur at some point doing scrolling or zooming. Sometimes in crashes as soon as I zoom/scroll. Sometimes I can zoom and scroll for a while until it crashes.
I know before iOS4 the UIKit was not thread safe and could not be used with CATiledLayers. See tech note My problem (i think) seems to be a thread issue. Surely UIKit can't be to blame?
Try to make the path property atomic.
ReplyDeleteAlso, you should probably modify drawRect to the following:
- (void)drawRect:(CGRect)rect
{
[[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:0.45] setStroke];//sets stroke color in current context
@synchronized(self) {
[self.path stroke];
}
}