Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat could cause [UIImage imageWithData] to crash when it comes back
    primarykey
    data
    text
    <p>I have this code in one of my <code>NSManagedObjects</code>:</p> <pre><code>if (self.tempImageStorage) { return self.tempImageStorage; } else if(self.imageData) { NSLog(@"%@ %d",self.imageData, self.imageData.length); self.tempImageStorage = [UIImage imageWithData:self.imageData]; return self.tempImageStorage; } </code></pre> <p>Occasionally, usually when I'm flipping through the images quickly, it will come back with an <code>EXC_BAD_ACCESS</code> on the 5th line (UIImage imageWithData line), and I can't po (printobject) self in the console, so I assume that the <code>NSMananagedObject</code> itself has been deallocated. What doesn't make sense is that it was able to reference self for the 2 ifs, and I even log the image data and its length just fine right before it. </p> <p>How could the <code>NSManagedObject</code> be deallocated in during that period since this is all happening on the same thread (and it's the main thread)?</p> <p>PS: I have Zombies enabled but it still doesn't let me po self.</p> <p>Code that sets the image data:</p> <pre><code>- (void) processRequest:(ASIHTTPRequest *) request { UIImage * orig = [UIImage imageWithData:[request responseData]]; CGSize targetSize = isPad()?CGSizeMake(446,150):CGSizeMake(320, 108); CGRect fourPanelSize = CGRectMake(0, 0, 1000, 336); CGImageRef imageRef = CGImageCreateWithImageInRect([orig CGImage], fourPanelSize); CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef); CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef); if (bitmapInfo == kCGImageAlphaNone || bitmapInfo == kCGImageAlphaLast) { bitmapInfo = kCGImageAlphaPremultipliedLast; } CGContextRef bitmap; bitmap = CGBitmapContextCreate(NULL, targetSize.width, targetSize.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo); CGContextDrawImage(bitmap, CGRectMake(1, 1, targetSize.width-2, targetSize.height-2), imageRef); CGImageRef ref = CGBitmapContextCreateImage(bitmap); UIImage* newImage = [UIImage imageWithCGImage:ref]; CGContextRelease(bitmap); CGImageRelease(ref); NSData * thumbData = UIImagePNGRepresentation(newImage); NSData * imageData = UIImagePNGRepresentation(orig); //Post notification on main thread since it will be updating the UI [[NSOperationQueue mainQueue] addOperationWithBlock:^{ self.tempImageThumbStorage = newImage; self.imageThumbnailData = thumbData; self.tempImageStorage = orig; self.imageData = imageData; [(AppDelegate*)[UIApplication sharedApplication].delegate saveContext]; NSMutableDictionary * userInfo = [[NSMutableDictionary alloc] initWithCapacity:1]; [userInfo setObject:[NSNumber numberWithBool:YES] forKey:@"status"]; [userInfo setObject:self forKey:@"comic"]; [[NSNotificationCenter defaultCenter] postNotificationName:PCRLoadMediahNotification object:self userInfo:userInfo]; strongSelf = nil; }]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload