I'm trying to save and restore cgcontext to avoid doing heavy drawing computations for a second time and I'm getting the error : CGGStackRestore: gstack underflow. What am I doing wrong? What is the correct way to do this?
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
if (initialized) {
CGContextRestoreGState(context);
//scale context
return;
}
initialized = YES;
//heavy drawing computation and drawing
CGContextSaveGState(context);
}