我在以下代码中遇到了崩溃问题(仅在 Ad-Hoc 构建中)。
- (void)drawPreviewInRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGColorRef strokeColor = [self.delegate.strokeColor CGColor];
CGFloat strokeWidth = self.delegate.strokeWidth;
CGFloat x = rect.size.width/2.0f;
CGFloat y = rect.size.height/2.0f;
CGPoint strokePoint = CGPointMake(x, y);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, strokeWidth);
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextMoveToPoint(context, strokePoint.x, strokePoint.y);
CGContextAddLineToPoint(context, strokePoint.x, strokePoint.y);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
崩溃日志显示如下图:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x10000008
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x39f535b0 objc_msgSend + 16
1 CoreGraphics 0x3237c3ec CGColorRetain + 12
2 CoreGraphics 0x3237c592 CGGStateSetStrokeColor + 38
该代码在开发环境中运行良好(在模拟器和设备上)。有什么理论吗?我在ARC下工作。