CATitledLayer 出现间歇性 EXC_BAD_ACCESS 异常

发布于 2025-01-08 05:23:56 字数 1272 浏览 0 评论 0原文

我的应用程序遇到了一些问题,它不断间歇性崩溃。下面的代码位于以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘人皮目录ツ 2025-01-15 05:23:56

尝试使 path 属性原子

另外,您可能应该将 drawRect 修改为以下内容:

- (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];
    }
}

Try to make the path property atomic.

Also, 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];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文