NSThread shared object issue

Posted by Chris Beeson on Stack Overflow See other posts from Stack Overflow or by Chris Beeson
Published on 2010-03-31T18:16:36Z Indexed on 2010/04/01 18:53 UTC
Read the original article Hit count: 544

Filed under:


I'm getting an “EXC_BAD_ACCESS” but just can't work out why, any help would be massive - thank you in advance.

The user takes a picture and I want to do some processing on it in another thread...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info


NSString *uid = [Asset stringWithUUID];

[_imageQueue setObject:img forKey:uid];

[NSThread detachNewThreadSelector:@selector(createAssetAsyncWithImage:) 

Then the new thread

-(void) createAssetAsyncWithImage:(NSString *)uid {

 NSAutoreleasePool * pool =[[NSAutoreleasePool alloc] init];

 if ([_imageQueue objectForKey:uid]) {
 Asset *asset = [Asset createAssetWithImage:[_imageQueue objectForKey:uid]];

 asset.uid = uid;

 [self performSelectorOnMainThread:@selector(asyncAssetCreated:)


 [pool release];

Which calls

    +(Asset *)createAssetWithImage:(UIImage *)img

     UIImage *masterImg = [GraphicSupport createThumbnailFromImage:img pixels:img.size.height/2];

     return newAsset;

And then this is where I keep getting the BAD_ACCESS

+(UIImage *)createThumbnailFromImage:(UIImage *)inImage pixels:(float)pixels{

 CGSize size = image.size;
 CGFloat ratio = 0;

 if (size.width > size.height) {

  ratio = pixels / size.width;
 else {
  ratio = pixels / size.height;

 CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);


 //NSAssert(image,@"image NULL");

 [image drawInRect:rect];

 return UIGraphicsGetImageFromCurrentImageContext(); 

It's image that is giving me all the complaints...

What am I doing wrong??

Many thanks in advance

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsthread