CGContext error trying to draw in touchesBegan

173 views Asked by At
- (void)drawRect:(CGRect)rect {

}

- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CGContextRef context = UIGraphicsGetCurrentContext();

    UITouch* touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];

    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);

    CGContextMoveToPoint(context, point.x, point.y);
    CGContextAddLineToPoint(context, point.x + 100, point.y);

    CGContextStrokePath(context);
}

And it gives me error

[Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. [Unknown process name] CGContextMoveToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. [Unknown process name] CGContextAddLineToPoint: invalid context 0x0. If you want to see the backtrace, please se CG_CONTEXT_SHOW_BACKTRACE environmental variable. [Unknown process name] CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

0

There are 0 answers