0

I'm trying to draw some bezier paths in my view's drawRect method, but I keep getting an invalid context error. I don't understand why, because I thought that there was always a context when drawRect is called. Am I missing something? This is the full implementation I have:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGFloat pattern[] = {5.0, 3.0};
    CGContextSetLineDash(context, 0.0, pattern, 2);

    // Set line color to be black
    [[UIColor blackColor] setStroke];

    //Stroke the bezier path for each plane
    for(SEPlaneView *plane in self.planes){        
        // Set line thickness and termination style
        [plane.planeBezier setLineWidth:1.0];
        [plane.planeBezier setLineCapStyle:kCGLineCapRound];

        [plane.planeBezier stroke];
    }

    CGContextRelease(context);
}
LunaEques
  • 178
  • 2
  • 8
  • 1
    One possibility - you should not be releasing the context. You don't own it. Also, make sure you are not explicitly calling `drawRect:`. – rmaddy Jun 20 '13 at 20:43
  • That worked. Thank you! We've been having memory errors, so I was releasing everything I could. Now I know not to do that. – LunaEques Jun 21 '13 at 13:35

0 Answers0