Reputation: 89
I use UIBezierPath
to draw a line. But having an error
This is my code:
UIBezierPath *aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(100, 100)];
[aPath addLineToPoint:CGPointMake(200, 200)];
[aPath closePath];
aPath.lineWidth = 5;
[[UIColor redColor] setStroke];
[aPath stroke];
This is error:
CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Upvotes: 0
Views: 246
Reputation: 5967
Rather than
[[UIColor redColor] setStroke];
use
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
Also you could do the same as-
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
UIBezierPath *aPath;
aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(0, 0)];
[aPath addLineToPoint:CGPointMake(size*2, 0)];
[aPath addLineToPoint:CGPointMake(size, size*2)];
[aPath closePath];
shapeLayer.path = aPath.CGPath;
shapeLayer.strokeColor = [[UIColor redColor] CGColor];
shapeLayer.fillColor = color;
shapeLayer.lineWidth = width;
[self addSublayer:shapeLayer];
Upvotes: 1
Reputation: 6704
Try this: In xcode add symbolic breakpoint to CGPostError
. (Add symbolic breakpoint, and to Symbol field type CGPostError
)
When error happen, debugger will stop code executions and you can check stack of methods calls and check parameters.
Also make sure you have imported QuartzCode
framework.
Upvotes: 0
Reputation: 14128
Add this like to setStrokeColor
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
Upvotes: 0