The following is a crash report I received from my crash reporting service, HockeyApp. The reason for the failure is a failure to save in PLSharedManagedObjectContext. I (think) I am doing all of my saves in the main app delegate managedObjectContext. Why is the PLSharedManagedObjectContext the one being saved to?
I think this is the relevant code:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
__ENTERING_METHOD__
DLog(@"info:%@",info);
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
__block UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
CGSize cropSize = CGSizeMake(320,320);
CGFloat previewWindowHeight = 100.0f;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block UIImage *previewImage;
if (originalImage) {
DLog(@"WE DO HAVE AN ORIGINAL IMAGE");
}
else {
DLog(@"WE DO NOT HAVE AN ORIGINAL IMAGE");
}
ImageEditor *imageEditor = [[ImageEditor alloc] initWithNibName:nil bundle:nil];
[imageEditor setRotateEnabled:NO];
[imageEditor setCheckBounds:NO];
[imageEditor setSourceImage:originalImage];
[imageEditor setPreviewHeight1:[NSNumber numberWithDouble:previewWindowHeight]];
[imageEditor setCropSize:cropSize];
imageEditor.doneCallback = ^(UIImage *editedImage, UIImage *originalImageMax1024, BOOL canceled){
picker.delegate = nil;
if(!canceled) {
if (editedImage) {
UIImage *scaledThumbnail = [HFImageEditorViewController getThumbnailForImage:editedImage size:CGSizeMake(PERSON_THUMBNAIL_SIZE,PERSON_THUMBNAIL_SIZE) round:PERSON_THUMBNAIL_ROUND];
[self setObjectCroppedImage:editedImage thumbnail:scaledThumbnail updateHeaderView:YES mocSave:NO];
[self setObjectMainImage:originalImageMax1024 mocSave:NO];
[Helper mocSave];
self.imageToShow = originalImage;
}
}
[Helper controller:self dismissControllerModal:YES];
};
[library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
if (!originalImage) {
originalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
}
[imageEditor setSourceImage:originalImage];
previewImage = [UIImage imageWithCGImage:[asset aspectRatioThumbnail]];
[imageEditor setPreviewImage:previewImage];
[imageEditor reset:NO];
//DLog(@"originalImage.imageOrientation:%d",originalImage.imageOrientation);
[picker pushViewController:imageEditor animated:YES];
} failureBlock:^(NSError *error) {
DLog(@"Failed to get asset from library");
if (originalImage) {
[imageEditor setSourceImage:originalImage];
[imageEditor setPreviewImage:nil];
[imageEditor reset:NO];
[picker pushViewController:imageEditor animated:YES];
}
else {
[Helper showSimpleAlertWithTitle:NSLocalizedString(@"Image Could Not Be Set", @"Image Could Not Be Set") message:NSLocalizedString(@"Failed to retrieve selected image asset from the Library.", @"Failed to retrieve selected image asset from the Library.")];
[Helper controller:self dismissControllerModal:YES];
}
}];
}
This is the crash log I am receiving:
Incident Identifier: 4DD4FE03-B8D4-4625-9039-64E4EE725AAB
CrashReporter Key: 129951E7-CF2A-4BB0-A8AB-7BA954275E29
Hardware Model: iPhone5,2
Process: MyApp [144]
Path: /Users/USER/MyApp.app/MyApp
Identifier: com.myCom.myApp
Version: 1.5.1
Code Type: ARM
Parent Process: launchd [1]
Date/Time: 2013-11-23 12:15:43 +0000
OS Version: iPhone OS 7.0.4 (11B554a)
Report Version: 104
Exception Type: SIGABRT
Exception Codes: #0 at 0x3a9031fc
Crashed Thread: 0
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to save context <PLSharedManagedObjectContext: 0x157b6110>: Error Domain=NSCocoaErrorDomain Code=134030 "The operation couldn’t be completed. (Cocoa error 134030.)" (null)'
Last Exception Backtrace:
0 CoreFoundation 0x2fff6e83 __exceptionPreprocess + 131
1 libobjc.A.dylib 0x3a3536c7 objc_exception_throw + 38
2 PhotoLibraryServices 0x3667441d __copy_helper_block_279 + 1
3 CoreData 0x2fdd1855 developerSubmittedBlockToNSManagedObjectContextPerform + 89
4 libdispatch.dylib 0x3a8380af _dispatch_client_callout + 23
5 libdispatch.dylib 0x3a83a9a9 _dispatch_main_queue_callback_4CF + 268
6 CoreFoundation 0x2ffc15b1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
7 CoreFoundation 0x2ffbfe7d __CFRunLoopRun + 1309
8 CoreFoundation 0x2ff2a471 CFRunLoopRunSpecific + 524
9 CoreFoundation 0x2ff2a253 CFRunLoopRunInMode + 106
10 GraphicsServices 0x34c642eb GSEventRunModal + 138
11 UIKit 0x327df845 UIApplicationMain + 1136
12 MyApp 0x0005b10b main (main.m:5)
13 libdyld.dylib 0x3a84cab7 start + 3
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3a9031fc __pthread_kill + 8
1 libsystem_c.dylib 0x3a8b402d abort + 76
2 MyApp 0x002235c7 uncaught_exception_handler + 27
3 CoreFoundation 0x2fff7185 __handleUncaughtException + 581
4 libobjc.A.dylib 0x3a353927 _objc_terminate() + 175
5 libc++abi.dylib 0x39d191b3 std::__terminate(void (*)()) + 79
6 libc++abi.dylib 0x39d18a09 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*) + 1
7 libobjc.A.dylib 0x3a35379b objc_exception_throw + 250
8 PhotoLibraryServices 0x3667441d __copy_helper_block_279 + 1
9 CoreData 0x2fdd1855 developerSubmittedBlockToNSManagedObjectContextPerform + 89
10 libdispatch.dylib 0x3a8380af _dispatch_client_callout + 23
11 libdispatch.dylib 0x3a83a9a9 _dispatch_main_queue_callback_4CF + 268
12 CoreFoundation 0x2ffc15b1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x2ffbfe7d __CFRunLoopRun + 1309
14 CoreFoundation 0x2ff2a471 CFRunLoopRunSpecific + 524
15 CoreFoundation 0x2ff2a253 CFRunLoopRunInMode + 106
16 GraphicsServices 0x34c642eb GSEventRunModal + 138
17 UIKit 0x327df845 UIApplicationMain + 1136
18 MyApp 0x0005b10b main (main.m:5)
19 libdyld.dylib 0x3a84cab7 start + 3
Thread 1:
0 libsystem_kernel.dylib 0x3a8f0838 kevent64 + 24
1 libdispatch.dylib 0x3a839623 _dispatch_mgr_thread + 39
Thread 2:
0 libsystem_kernel.dylib 0x3a8f0a84 mach_msg_trap + 20
1 CoreFoundation 0x2ffc1559 __CFRunLoopServiceMachPort + 157
2 CoreFoundation 0x2ffbfc79 __CFRunLoopRun + 793
3 CoreFoundation 0x2ff2a471 CFRunLoopRunSpecific + 524
4 CoreFoundation 0x2ff6e0db CFRunLoopRun + 98
5 CoreMotion 0x305e2369 CLSF_thorntonUpdate_6x6 + 57225
6 libsystem_pthread.dylib 0x3a969c5d _pthread_body + 141
7 libsystem_pthread.dylib 0x3a969bcf _pthread_start + 102
8 libsystem_pthread.dylib 0x3a967cd0 thread_start + 8
Thread 3:
0 libsystem_kernel.dylib 0x3a903c7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3a967cc4 start_wqthread + 8
Thread 4:
0 libsystem_kernel.dylib 0x3a903c7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3a967cc4 start_wqthread + 8
Thread 5:
0 libsystem_kernel.dylib 0x3a8f0a84 mach_msg_trap + 20
1 CoreFoundation 0x2ffc1559 __CFRunLoopServiceMachPort + 157
2 CoreFoundation 0x2ffbfc79 __CFRunLoopRun + 793
3 CoreFoundation 0x2ff2a471 CFRunLoopRunSpecific + 524
4 CoreFoundation 0x2ff2a253 CFRunLoopRunInMode + 106
5 Foundation 0x309654c1 +[NSURLConnection _resourceLoadLoop:] + 320
6 Foundation 0x309dac37 __NSThread__main__ + 1063
7 libsystem_pthread.dylib 0x3a969c5d _pthread_body + 141
8 libsystem_pthread.dylib 0x3a969bcf _pthread_start + 102
9 libsystem_pthread.dylib 0x3a967cd0 thread_start + 8
Thread 6:
0 libsystem_kernel.dylib 0x3a903440 __select + 20
1 libsystem_pthread.dylib 0x3a969c5d _pthread_body + 141
2 libsystem_pthread.dylib 0x3a969bcf _pthread_start + 102
3 libsystem_pthread.dylib 0x3a967cd0 thread_start + 8
Thread 7:
0 libsystem_kernel.dylib 0x3a903c7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3a967cc4 start_wqthread + 8
Thread 8:
0 libsystem_kernel.dylib 0x3a8f0ad4 semaphore_wait_trap + 8
1 MediaToolbox 0x31419a0f fpa_AsyncMovieControlThread + 1755
2 CoreMedia 0x30556217 figThreadMain + 195
3 libsystem_pthread.dylib 0x3a969c5d _pthread_body + 141
4 libsystem_pthread.dylib 0x3a969bcf _pthread_start + 102
5 libsystem_pthread.dylib 0x3a967cd0 thread_start + 8
Thread 9:
0 libsystem_kernel.dylib 0x3a903c7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3a967cc4 start_wqthread + 8
Thread 0 crashed with ARM Thread State:
pc: 0x3a9031fc r7: 0x27dae3a4 sp: 0x27dae398 r0: 0x00000000
r1: 0x00000000 r2: 0x00000000 r3: 0xffffffff r4: 0x00000006
r5: 0x3c73018c r6: 0x15734ff0 r8: 0x32d7cdb2 r9: 0x3c730e30
r10: 0x32d62122 r11: 0x0000000e ip: 0x00000148 lr: 0x3a96aa53
cpsr: 0x00000010
EDIT: I think this code in ImageEditor may have something to do with it:
- (IBAction)doneAction:(id)sender
{
__ENTERING_METHOD__
self.view.userInteractionEnabled = NO;
[self startTransformHook];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
CGImageRef resultRef = [HFImageEditorViewController newTransformedImage:self.imageView.transform sourceImage:self.sourceImage.CGImage sourceSize:self.sourceImage.size sourceOrientation:self.sourceImage.imageOrientation outputWidth:self.outputWidth ? self.outputWidth : self.sourceImage.size.width cropSize:self.cropSize imageViewSize:self.imageView.bounds.size];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *transform = [UIImage imageWithCGImage:resultRef scale:1.0 orientation:UIImageOrientationUp];
CGImageRelease(resultRef);
UIImage *scaledThumbnail = [HFImageEditorViewController getThumbnailForImage:transform size:_thumbnailSize round:_thumbnailRound];
self.view.userInteractionEnabled = YES;
if(self.doneCallback) {
self.doneCallback(transform, _sourceImage, NO);
}
[self endTransformHook];
});
});
}
+ (UIImage*)getThumbnailForImage:(UIImage*)mySourceImage size:(CGSize)size round:(BOOL)round {
//TODO THIS SHOULD BE MOVED TO THE BACKGROUND
UIImage *scaledImage = [HFImageEditorViewController scaledImage:mySourceImage toSize:size withQuality:kCGInterpolationHigh];
if (round) {
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = CGRectMake(0, 0, scaledImage.size.width, scaledImage.size.height);
imageLayer.contents = (id) scaledImage.CGImage;
imageLayer.masksToBounds = YES;
imageLayer.cornerRadius = scaledImage.size.width/2;
UIGraphicsBeginImageContext(scaledImage.size);
[imageLayer renderInContext:UIGraphicsGetCurrentContext()];
scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return scaledImage;
}
PLSharedManagedObjectContext
appears to be an undocumented class that's part of PhotoLibraryServices.framework
. That framework is itself undocumented, but the fact that it shows up in your backtrace implicates it.
As a result I don't think that this exception has anything really to do with your Core Data code. PhotoLibraryServices is using Core Data internally somewhere, and failing to do so. This might mean that you're doing something wrong with your photo handling, or it might be a framework bug. Either way, looking at your own Core Data code will almost certainly miss the point.
Having said that, there's also an indication that a performBlock
call might have been involved somehow. Depending on what your mocSave
method does, there might be a connection.
User contributions licensed under CC BY-SA 3.0