NSThread shared object issue
- by Chris Beeson
Hi,
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:)
toTarget:self
withObject:uid];
}
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:)
withObject:asset
waitUntilDone:YES];
}
[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);
UIGraphicsBeginImageContext(rect.size);
//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