我正在使用CATiledLayer作为我的UIView的背景层,我已将其放入UIScrollView。在我的视图的init方法中,我创建了绘制简单线条的CGPathRef对象。当我试图在drawLayer:inContext中绘制此路径时,它在滚动/缩放时偶尔会与EXEC_BAD_ACCESS(很少)一起崩溃。CATiledLayer在绘制先前准备好的CGPath时崩溃
代码是很简单的,我使用的唯一标准CG *功能:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
tiledLayer.levelsOfDetail = 10;
tiledLayer.levelsOfDetailBias = 5;
tiledLayer.tileSize = CGSizeMake(512.0, 512.0);
CGMutablePathRef mutablePath = CGPathCreateMutable();
CGPathMoveToPoint(mutablePath, nil, 0, 0);
CGPathAddLineToPoint(mutablePath, nil, 700, 700);
path = CGPathCreateCopy(mutablePath);
CGPathRelease(mutablePath);
}
return self;
}
+ (Class) layerClass {
return [CATiledLayer class];
}
- (void) drawRect:(CGRect)rect {
}
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1);
CGContextFillRect(ctx, self.bounds);
CGContextSetLineWidth(ctx, 5);
CGContextAddPath(ctx, path);
CGContextDrawPath(ctx, kCGPathStroke);
}
- (void)dealloc {
[super dealloc];
}
更新: 我已经noiced一种只存在于iOS 5的这个问题,它的工作原理罚款4.3
调试EXEC_BAD_ACCESS很简单,当你打开NSZombieEnabled时,它会告诉你哪个被释放的变量被调用。 – Wolfert 2011-12-16 12:03:45
但在这段代码中,不可能对内存做一些坏事,无论如何它只发生在CATiledLayer和多线程中。 – 2011-12-16 13:04:13