Greg
Greg

Reputation: 1296

CALayer renderInContext: causing unknown crash

The entire block of code consists of the following:

    CGSize layerSize = [webview sizeThatFits:CGSizeZero];

    if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f) {
        UIGraphicsBeginImageContextWithOptions(layerSize, NO, 2.0f);
    } 
    else {
          UIGraphicsBeginImageContext(layerSize);
    }

    [webview.layer renderInContext:UIGraphicsGetCurrentContext()];

    screenshot = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

but after testing, this line is the one causing the problem:

    [webview.layer renderInContext:UIGraphicsGetCurrentContext()];

The app crashes with no reason listed in the console, and using @try @catch @finally comes up with nothing. I imported Quartzcore in AppDelegate.h, if that has anything to do with it. The app works fine in the simulator, but crashes when run on a real device.

Upvotes: 6

Views: 3864

Answers (2)

Madhur Sodhi
Madhur Sodhi

Reputation: 121

try

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

Upvotes: 0

akishnani
akishnani

Reputation: 86

@Greg : seems like a memory overflow issue on device since device is memory constrained while simulator runs with different memory configuration , i am running into the same - this can happen for long web pages , any ideas how to solve it ?

does anyone what is max width and height [CALayer renderInContext] can handle on actual device (iphone retina or non-retina) before it crashes ?

Upvotes: 3

Related Questions