CALayer renderInContext: causing unknown crash
Asked Answered
G

2

6

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.

Gallicanism answered 11/3, 2012 at 3:49 Comment(3)
Crashes with what? Does the console print anything? Is it EXC_BAD_ACCESS, or SIGABRT, or an NSExceptionThrow?Corso
the console doesn't print anything, and nothing pops up in Xcode. I'm just totally confused on what is happening, so I was wondering if I was doing something wrong.Gallicanism
HI,Have you found a solution for this,im also having same problem?If so pls share the solutionSottish
J
3

@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 ?

Jeromejeromy answered 13/3, 2012 at 20:1 Comment(1)
Me also have the some problem, but this problem is only coming in horizontal mode,Lesser
G
0

try

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

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
Geter answered 2/1, 2014 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.