CATitledLayer 出现间歇性 EXC_BAD_ACCESS 异常
我的应用程序遇到了一些问题,它不断间歇性崩溃。下面的代码位于以 CATiledLayer 作为其支持层的 UIView 中:
- (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];
}
我收到以下错误代码:
Single stepping until exit from function _ZN2CG4Path15apply_transformERK17CGAffineTransform, which has no line number information.
错误发生时似乎没有任何模式。它似乎可能发生在滚动或缩放的某个时刻。有时当我缩放/滚动时就会崩溃。有时我可以缩放和滚动一段时间,直到崩溃。
我知道在 iOS4 之前,UIKit 不是线程安全的,不能与 CATiledLayers 一起使用。请参阅技术说明 我的问题(我认为)似乎是线程问题。 UIKit 肯定不能受到指责吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使
path
属性原子
。另外,您可能应该将
drawRect
修改为以下内容:Try to make the
path
propertyatomic
.Also, you should probably modify
drawRect
to the following: