This @try-@catch block in my viewDidLoad crashes with EXC_BAD_ACCESS when the return; is executed in the catch and the alert doesn’t show either:
@try
{
errorText = @"thumbnails_array";
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
self.thumbnails_array = [unarchiver decodeObjectForKey:@"thumbnails_array"];
[unarchiver finishDecoding];
[unarchiver release];
errorText = @"ThumbNailViewController";
archivePath = [app.phojoArchiveDir stringByAppendingPathComponent:@"ThumbNailViewController.archive"];
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
[unarchiver decodeObjectForKey:@"self"];
[unarchiver finishDecoding];
[unarchiver release];
errorText = @"assetsGroupURL";
archivePath = [app.phojoArchiveDir stringByAppendingPathComponent:@"assetsGroupURL.archive"];
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
app.assetsGroupURL = [unarchiver decodeObjectForKey:@"assetsGroupURL"];
[unarchiver finishDecoding];
[unarchiver release];
}
@catch (NSException *exception)
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Phojo is unable to restore the previous editing session." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@"Exception %@ thrown while unarchving %@: Reason: %@ Items in userInfo = %d Stack Trace: %@", [exception name], errorText, [exception reason], [[exception userInfo] count], [NSThread callStackSymbols]);
[self.thumbnails_array release];
self.thumbnails_array = nil;
[app.assetsGroupURL release];
app.assetsGroupURL = nil;
return;
}
This code is run in the viewDidLoad to retrieve data that have been archived during a previous run of the app. I’ve gotten an exception in this code stating that an archive is uncomprehensible. But with it crashing there is no way to get the app to run at all since it crashes on startup as well on the catch. Any ideas?
Either your
assetsGroupURLorthumbnails_arrayproperties (or both) are declared asretain. That’s fine, but it means that when you call both[self.theProperty release]andself.theProperty = nil, you’re releasingthePropertytwice: the second call is using theretain-generated setter and implicitly callingreleaseon its current value as well. Remove thereleasecalls and you should no longer see the EXC_BAD_ACCESS.