Debugging NSoperation BAD ACCESS within graphics context

Posted by Joe on Stack Overflow See other posts from Stack Overflow or by Joe
Published on 2010-03-22T18:21:11Z Indexed on 2010/03/22 18:31 UTC
Read the original article Hit count: 430

Filed under:
|

I tried everything to debug this one but I can't get to the bottom of it.

This code lives in a subclass of NSOperation which is processed from a queue:

(borders is an ivar NSArray containing 5 UIimage objects)


NSMutableArray *images = [[NSMutableArray alloc] init];

for (unsigned i = 0; i < 5; i++)
    {       

    CGSize size = CGSizeMake(60, 60);
    UIGraphicsBeginImageContext(size);

    CGPoint thumbPoint = CGPointMake(6, 6);

    [controller.image drawAtPoint:thumbPoint];

    CGPoint borderPoint = CGPointMake(0, 0);
    [[borders objectAtIndex:i] drawAtPoint:borderPoint];

    [images addObject:UIGraphicsGetImageFromCurrentImageContext()];

    UIGraphicsEndImageContext();

}

[images release];

The code works fine most of the time but when I push the iphone by access subviews and pressing lots of buttons on the UI I either get this exception which is trapped by the operation:

Exception Load view: *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil

or I get this:

Program received signal:  “EXC_BAD_ACCESS”.

The exception is caused because UIGraphicsGetImageFromCurrentImageContext() return nil.

I don't know how to debug the EXC_BAD_ACCESS but I'm guessing that this error (in fact both of these errors) is caused by low memory. The debugger stops at the line:

    [controller.image drawAtPoint:thumbPoint];

As I mentioned I've trapped the exception so I can live with that but the EXC_BAD_ACCESS is more serious.

IF this is memory related how can I tell and is it possible to increase the memory available to NSOperation?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c