CGContextFillEllipseInRect: invalid context
<p>when I launch my app, I keep getting this CGContextFillEllipseInRect: invalid context error. My app is simply to make the circle 'pinchable'.</p>

<p>The debugger shows me this:</p>

<pre><code>[Session started at 2010-05-23 18:21:25 +0800.]
2010-05-23 18:21:27.140 Erase[8045:207] I'm being redrawn.
Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] &lt;Error&gt;: CGContextFillEllipseInRect: invalid context
2010-05-23 18:21:27.144 Erase[8045:207] New value of counter is 1
2010-05-23 18:21:27.144 Erase[8045:207] I'm being redrawn.
Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] &lt;Error&gt;: CGContextFillEllipseInRect: invalid context
2010-05-23 18:21:27.144 Erase[8045:207] New value of counter is 2
2010-05-23 18:21:27.144 Erase[8045:207] I'm being redrawn.
Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] &lt;Error&gt;: CGContextFillEllipseInRect: invalid context
2010-05-23 18:21:27.144 Erase[8045:207] New value of counter is 3
2010-05-23 18:21:27.145 Erase[8045:207] I'm being redrawn.
Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] &lt;Error&gt;: CGContextFillEllipseInRect: invalid context
2010-05-23 18:21:27.145 Erase[8045:207] New value of counter is 4
2010-05-23 18:21:27.148 Erase[8045:207] I'm being redrawn.
Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] &lt;Error&gt;: CGContextFillEllipseInRect: invalid context
2010-05-23 18:21:27.149 Erase[8045:207] New value of counter is 5
2010-05-23 18:21:27.150 Erase[8045:207] I'm being redrawn.
Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] &lt;Error&gt;: CGContextFillEllipseInRect: invalid context
2010-05-23 18:21:27.150 Erase[8045:207] New value of counter is 6
</code></pre>

<p>My implementation file is:</p>

<pre><code>//
//  ImageView.m
//  Erase
//

#import "ImageView.h"
#import "EraseViewController.h"

@implementation ImageView


-(void)setNewRect:(CGRect)anotherRect{
    newRect = anotherRect;
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        newRect = CGRectMake(0,0,0,0);
        ref = UIGraphicsGetCurrentContext();
    }
    return self;
}



- (void)drawRect:(CGRect)rect {
    static int counter = 0;
    CGRect veryNewRect = CGRectMake(30.0, 210.0, 60.0, 60.0);
    NSLog(@"I'm being redrawn.");

    if (counter == 0){
        CGContextFillEllipseInRect(ref, veryNewRect);
    }
    else{
        CGContextFillEllipseInRect(ref, rect);
    }

    counter++;
    NSLog(@"New value of counter is %d", counter);
}

- (void)setNeedsDisplay{
    [super setNeedsDisplay];
    [self drawRect:newRect];
}

- (void)dealloc {
    [super dealloc];
}


@end
</code></pre>

<p>I've got two questions:
1) Why is it updating counter 6 times? I removed the line <code>[super setNeedsDisplay];</code> but it becomes 4 times.
2) What is that invalid context error?</p>

<p>Thanks guys.</p>
