Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in iphone: Assertion failed: (s->stack->next != NULL), function CGGStackRestore, file Context/CGGStack.c, line 116

My code is as below. I get the error as

Assertion failed: (s->stack->next != NULL), function CGGStackRestore, file Context/CGGStack.c, line 116.

Code:

 CGPDFPageRef page = CGPDFDocumentGetPage(document, i+1);
            CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
            CGFloat pdfScale = width/pageRect.size.width;
            pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);  
            pageRect.origin = CGPointZero;
            UIGraphicsBeginImageContext(pageRect.size);
            CGContextRef context = UIGraphicsGetCurrentContext();   

            // White BG  CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);  CGContextFillRect(context,pageRect);   CGContextSaveGState(context); 

            CGContextTranslateCTM(context, 0.0, pageRect.size.height);
            CGContextScaleCTM(context, 1.0, -1.0);
            CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, pageRect, 0, true));
            CGContextDrawPDFPage(context, page);  
            CGContextRestoreGState(context); 

            UIImage *thm = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext(); 
            NSLog(@"Image %@",thm);
            pdfImage = [[UIImageView alloc] initWithImage:thm];
            NSLog(@"Image View: %@",pdfImage);
            [self.view addSubview:pdfImage];
            [self.view reloadInputViews
];

Please Help.

like image 293
Aditya Athavale Avatar asked Sep 07 '11 10:09

Aditya Athavale


1 Answers

There is no CGContextSaveGState before CGContextRestoreGState!

like image 110
Felix Avatar answered Oct 11 '22 05:10

Felix