ios core data NSFetchedResultsControllerDelegate crash - iphone

I am keep getting this error for NSFetchedResultsControllerDelegate.
not sure what to do with it, since it happen sporadically.
I do create the records synchronized, but still ..
any ideas why could this be?
- (Activity *)createActivityWithDictionary:(NSDictionary*)dict
{
#synchronized([DBController sharedManaged])
{
Activity *act = [Activity activityWithDictionary:dict inManagedObjectContext:self.managedObjectContext];
[self saveContext];
return act;
}
}
Date/Time: 2012-09-18 22:55:53.686 -0700
OS Version: iPhone OS 5.1.1 (9B206)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3724188f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x34f46259 objc_exception_throw + 33
2 CoreFoundation 0x37244a9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x37243915 ___forwarding___ + 301
4 CoreFoundation 0x3719e650 _CF_forwarding_prep_0 + 48
5 CoreData 0x36a78f4d -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 2401
6 Foundation 0x37aa64ff __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 19
7 CoreFoundation 0x3720d547 ___CFXNotificationPost_block_invoke_0 + 71
8 CoreFoundation 0x37199097 _CFXNotificationPost + 1407
9 Foundation 0x37a1a3eb -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
10 CoreData 0x36a00839 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 77
11 CoreData 0x36a0031d -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 305
12 CoreData 0x36a09d01 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 1245
13 CoreData 0x369fd145 -[NSManagedObjectContext save:] + 201
14 PalFinds 0x000a57cb -[DBController saveContext] (DBController.m:75)
15 PalFinds 0x000a8dff -[DBController createActivityWithDictionaries:] (DBController.m:852)
16 PalFinds 0x00086649 -[PFMe finishRequest:andRestConnection:] (PFMe.m:1986)
17 PalFinds 0x0002e17d -[RestConnection connectionDidFinishLoading:] (RestConnection.m:326)
18 Foundation 0x37addc29 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 + 17
19 Foundation 0x37a356d9 -[NSURLConnectionInternalConnection invokeForDelegate:] + 29
20 Foundation 0x37a356a3 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
21 Foundation 0x37a355c5 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 61
22 CFNetwork 0x36ed97f5 URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*) + 193
23 CFNetwork 0x36ece4a5 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 425
24 CFNetwork 0x36ece599 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 669
25 CFNetwork 0x36ece599 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 669
26 CFNetwork 0x36ece1a3 URLConnectionClient::processEvents() + 107
27 CFNetwork 0x36ece0d9 MultiplexerSource::perform() + 157
28 CoreFoundation 0x37215ad3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x3721529f __CFRunLoopDoSources0 + 215
30 CoreFoundation 0x37214045 __CFRunLoopRun + 653
31 CoreFoundation 0x371974a5 CFRunLoopRunSpecific + 301
32 CoreFoundation 0x3719736d CFRunLoopRunInMode + 105
33 GraphicsServices 0x33956439 GSEventRunModal + 137
34 UIKit 0x30f43cd5 UIApplicationMain + 1081
35 PalFinds 0x000038bf main (main.mm:14)
36 PalFinds 0x00003878 start + 40

Looks like it's trying to call the delegate back and the delegate isn't implementing a method it's supposed to.
I'm thinking either controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: or controllerDidChangeContent:
Did you implement those methods in your NSFetchedResultsControllerDelegate?

I know this might seem far fetched BUT I had a very similar problem and I had all those methods implemented and then I realized I had my release commented out for the fetchedREsultsController...once I put that back in no more sigbart and works like a charm.
All I'm saying is that sometimes the error isn't always the obvious.
We would need to see a bit more code to figure it out. Thanks.

Related

AFNetworking and NSBlockOperation crash

Running an iPhone app using the latest version of AFNetworking, the most popular crash according to Crashlytics is involving NSBlockOperation. I am unsure whether AFNetworking is responsible or not. The log from Crashlytics:
Exception Type: EXC_BAD_ACCESS Code: KERN_INVALID_ADDRESS at 0x2985118298
5com.apple.NSURLConnectionLoader Crashed
0 libobjc.A.dylib objc_msgSend + 9
1 Foundation -[NSBlockOperation main] + 200
2 Foundation -[__NSOperationInternal start] + 840
3 Foundation -[_NSCFURLProtocolBridgeWithTrampoline processEventQ] + 344
4 Foundation -[_NSCFURLProtocolBridgeWithTrampoline pushEvent:from:] + 298
5 Foundation -[_NSCFURLProtocolBridge stop] + 88
6 Foundation _bridger + 64
7 CFNetwork __block_global_7 + 24
8 CFNetwork __block_global_8 + 12
9 CFNetwork ___performAsync_block_invoke_068 + 18
10 CoreFoundation CFArrayApplyFunction + 176
11 CFNetwork RunloopBlockContext::perform() + 74
12 CFNetwork MultiplexerSource::perform() + 188
13 ... CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
14 CoreFoundation __CFRunLoopDoSources0 + 212
15 CoreFoundation __CFRunLoopRun + 646
16 CoreFoundation CFRunLoopRunSpecific + 356
17 CoreFoundation CFRunLoopRunInMode + 104
18 Foundation +[NSURLConnection(Loader) _resourceLoadLoop:] + 308
19 Foundation __NSThread__main__ + 972
20 libsystem_c.dylib _pthread_start + 308
Let me know if you need more logs. Can anybody direct me in the direction to avoid this crash? Out of 2500 users 76 users has been affected.
Update Sept 17:
Seems like this guy is having the same problem:
iOS Blocks Async Callbacks Causing Crash after View Controller is deallocated.

Need help in finding crash cause

Below are the crash logs from an iPad. I'm getting this crash randomly while I'm pushing and popping out a UIViewController from Navigation controller. Any help/pointer is appreciated.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x31430386 _ZL12realizeClassP7class_t + 34
1 libobjc.A.dylib 0x314303e6 _ZL12realizeClassP7class_t + 130
2 libobjc.A.dylib 0x3142a836 prepareForMethodLookup + 74
3 libobjc.A.dylib 0x3142a740 lookUpMethod + 40
4 libobjc.A.dylib 0x3142a70c _class_lookupMethodAndLoadCache3 + 12
5 libobjc.A.dylib 0x31429fc4 objc_msgSend_uncached + 20
6 UIKit 0x3186553e -[UINavigationItem _accumulateViewsFromItems:isLeft:refreshViews:] + 270
7 UIKit 0x31851244 -[UINavigationItem _updateViewsForBarSizeChangeAndApply:] + 124
8 UIKit 0x319e023a __33-[UINavigationBar layoutSubviews]_block_invoke_0 + 250
9 UIKit 0x31838b46 +[UIView(Animation) _performWithoutAnimation:] + 62
10 UIKit 0x3184d2e2 -[UINavigationBar layoutSubviews] + 382
11 UIKit 0x31814f30 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 176
12 CoreFoundation 0x315431f4 -[NSObject performSelector:withObject:] + 36
13 QuartzCore 0x35459a9e -[CALayer layoutSublayers] + 210
14 QuartzCore 0x354596b6 CA::Layer::layout_if_needed(CA::Transaction*) + 210
15 QuartzCore 0x3545d83c CA::Context::commit_transaction(CA::Transaction*) + 220
16 QuartzCore 0x3545d578 CA::Transaction::commit() + 308
17 QuartzCore 0x354554b2 CA:::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 50
18 CoreFoundation 0x315b8b14 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
19 CoreFoundation 0x315b6d50 __CFRunLoopDoObservers + 252
20 CoreFoundation 0x315b70aa __CFRunLoopRun + 754
21 CoreFoundation 0x3153a49e CFRunLoopRunSpecific + 294
22 CoreFoundation 0x3153a366 CFRunLoopRunInMode + 98
23 GraphicsServices 0x32a13432 GSEventRunModal + 130
24 UIKit 0x3183fcce UIApplicationMain + 1074
25 SmartClassTPS 0x000b551a main (main.m:16)
26 SmartClassTPS 0x000b5170 start + 32
Was able to figure out long back but forgot to update here. KVO observer not removed! Silly me :-|. BTW thanks for the support. SO rocks.
Most probably you forgot to clear some delegates before releasing an object.

Core Data causing crash on iPhone 3

I'm getting a strange error with core data. Sometimes, but not all the time my app will crash when I try to access a core data object.
It happens regularly on iPhone 3's and only sometimes on iPhone 4's. I looked at my device log and narrowed it down to an issue with core data. The line the logs refer to is below, tripInstructor is a core data object, its a property of the AppManager class. Not sure if this makes a big difference but I do declare the property as being "nonatomic, retain".
Thanks for any advice
[self.supervisorLbl setText:[AppManager sharedAppManager].tripInstructor.name];
Date/Time: 2011-06-12 20:55:24.865 +1000
OS Version: iPhone OS 4.3.3 (8J2)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x33e8da1c pthread_kill + 8
1 libsystem_c.dylib 0x35e5b3b4 pthread_kill + 52
2 libsystem_c.dylib 0x35e53bf8 abort + 72
3 libstdc++.6.dylib 0x33508a64 __gnu_cxx::__verbose_terminate_handler() + 376
4 libobjc.A.dylib 0x33f1106c _objc_terminate + 104
5 libstdc++.6.dylib 0x33506e36 _cxxabiv1::_terminate(void (*)()) + 46
6 libstdc++.6.dylib 0x33506e8a std::terminate() + 10
7 libstdc++.6.dylib 0x33506efe __cxa_rethrow + 62
8 libobjc.A.dylib 0x33f10fd8 objc_exception_rethrow + 4
9 CoreData 0x35624f66 _PFFaultHandlerLookupRow + 1450
10 CoreData 0x356799ba -[NSFaultHandler fulfillFault:withContext:] + 14
11 CoreData 0x35678782 _PF_FulfillDeferredFault + 354
12 CoreData 0x35623f18 _sharedIMPL_pvfk_core + 52
13 CoreData 0x35626b68 _pvfk_5 + 4
14 eLogger 0x0000e346 -[VicLogVC viewWillAppear:] (VicLogVC.m:207)
15 UIKit 0x3636bf14 -[UINavigationController _startTransition:fromViewController:toViewController:] + 604
16 UIKit 0x3636bc3c -[UINavigationController _startDeferredTransitionIfNeeded] + 176
17 UIKit 0x3635dd56 -[UINavigationController pushViewController:transition:forceImmediate:] + 634
18 UIKit 0x3635dacc -[UINavigationController pushViewController:animated:] + 28
19 eLogger 0x00025332 -[TripScreenVC _populateAndDisplayVicLog] (TripScreenVC.m:221)
20 eLogger 0x00025492 -[TripScreenVC _determineLogScreen] (TripScreenVC.m:258)
21 eLogger 0x000255d4 -[TripScreenVC buttonPressed:] (TripScreenVC.m:307)
22 CoreFoundation 0x30d4356a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
23 UIKit 0x36343ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
24 UIKit 0x36343e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
25 UIKit 0x36343e34 -[UIControl sendAction:to:forEvent:] + 32
26 UIKit 0x36343b86 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
27 UIKit 0x3634441c -[UIControl touchesEnded:withEvent:] + 336
28 UIKit 0x36342bee -[UIWindow _sendTouchesForEvent:] + 362
29 UIKit 0x36342568 -[UIWindow sendEvent:] + 256
30 UIKit 0x3632b30c -[UIApplication sendEvent:] + 292
31 UIKit 0x3632ac4c _UIApplicationHandleEvent + 5084
32 GraphicsServices 0x34e2be70 PurpleEventCallback + 660
33 CoreFoundation 0x30daaa90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 20
34 CoreFoundation 0x30dac838 __CFRunLoopDoSource1 + 160
35 CoreFoundation 0x30dad606 __CFRunLoopRun + 514
36 CoreFoundation 0x30d3debc CFRunLoopRunSpecific + 224
37 CoreFoundation 0x30d3ddc4 CFRunLoopRunInMode + 52
38 GraphicsServices 0x34e2b418 GSEventRunModal + 108
39 GraphicsServices 0x34e2b4c4 GSEventRun + 56
40 UIKit 0x36355d62 -[UIApplication _run] + 398
41 UIKit 0x36353800 UIApplicationMain + 664
42 eLogger 0x00002ff8 main (main.m:14)
43 eLogger 0x00002fa0 start + 32
You are likely holding on to an invalid reference to a managed object, it looks like it was turned into a fault by the managed object context, perhaps after calling -save: or -reset on the context.
If you deleted an object from your store, and still held a reference to the managed object in the ivar then that could be the cause of this error. The object will be deleted by CoreData and turned into a fault when -save: is called (at which point you should nil and reset your ivars). But, when you try to fault the object (by accessing one or more of it's properties) it won't be found in the store because you deleted it.

Core Data save exception

I got very weird issue with managedObjectContext:save. It hasn't happened at the first time I save the context, it only happens at some point of my program. Could you help me to know why it happened and where should I should find a bug in my code? Thanks.
Here is the log:
-[NSCFNumber UTF8String]: unrecognized selector sent to instance 0x5a64110
2011-05-19 16:02:43.235 DMC to Go[98212:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber UTF8String]: unrecognized selector sent to instance 0x5a64110'
*** Call stack at first throw:
(
0 CoreFoundation 0x015d85a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0172c313 objc_exception_throw + 44
2 CoreFoundation 0x015da0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01549966 ___forwarding___ + 966
4 CoreFoundation 0x01549522 _CF_forwarding_prep_0 + 50
5 CoreData 0x002f870f -[NSSQLiteConnection execute] + 1231
6 CoreData 0x0034aebd -[NSSQLiteConnection updateRow:] + 365
7 CoreData 0x00349e64 -[NSSQLConnection performAdapterOperations:] + 180
8 CoreData 0x00349b0e -[NSSQLCore _performChangesWithAdapterOps:] + 494
9 CoreData 0x003485ea -[NSSQLCore performChanges] + 410
10 CoreData 0x00342038 -[NSSQLCore saveChanges:] + 216
11 CoreData 0x00300199 -[NSSQLCore executeRequest:withContext:error:] + 409
12 CoreData 0x003b070b -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 3691
13 CoreData 0x00338948 -[NSManagedObjectContext save:] + 712
14 DMC to Go 0x0000313b -[dmcIpadAppDelegate saveManagedObjectChanges] + 107
15 DMC to Go 0x00020dc5 +[DmcIpadAppDelegate saveManagedObjectChanges] + 117
16 DMC to Go 0x00027883 -[DownloadFileService observeValueForKeyPath:ofObject:change:context:] + 867
17 Foundation 0x00fae1e4 NSKeyValueNotifyObserver + 361
18 Foundation 0x00fadca6 NSKeyValueDidChange + 384
19 Foundation 0x00f943e2 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 123
20 DMC to Go 0x0002c674 -[DownloadManager connectionDidFinishLoading:] + 836
21 Foundation 0x00fd4112 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
22 Foundation 0x00fd406b _NSURLConnectionDidFinishLoading + 133
23 CFNetwork 0x01dd948e _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 220
24 CFNetwork 0x01ea46e1 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 293
25 CFNetwork 0x01dcfc80 _ZN19URLConnectionClient13processEventsEv + 100
26 CFNetwork 0x01dcfacf _ZN17MultiplexerSource7performEv + 251
27 CoreFoundation 0x015b98ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
28 CoreFoundation 0x0151788b __CFRunLoopDoSources0 + 571
29 CoreFoundation 0x01516d86 __CFRunLoopRun + 470
30 CoreFoundation 0x01516840 CFRunLoopRunSpecific + 208
31 CoreFoundation 0x01516761 CFRunLoopRunInMode + 97
32 GraphicsServices 0x0202a1c4 GSEventRunModal + 217
33 GraphicsServices 0x0202a289 GSEventRun + 115
34 UIKit 0x00838c93 UIApplicationMain + 1160
35 DMC to Go 0x00001f59 main + 121
36 DMC to Go 0x00001ed5 start + 53
37 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c
Make sure you have no warnings
Put breakpoints in your code where you think you are setting an NSString on your object
And/Or NSLog %# the class of NSString properties of your core data objects and make sure it is some variation of an NSString. (NSLog(#"%#", [obj.property class]);)
What is happening is something that you are saving has an NSNumber object in place of an NSString. Since NSNumber does not respond to UTF8String your application is crashing.

Application Crashing due to EXC_BAD_ACCESS

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x00004420 objc_msgSend + 24
1 CoreFoundation 0x000042a6 CFRetain + 54
2 CoreFoundation 0x0000a9f0 __CFBasicHashStandardRetainValue + 8
3 CoreFoundation 0x000054c0 __CFBasicHashAddValue + 100
4 CoreFoundation 0x00006184 CFBasicHashAddValue + 276
5 CoreFoundation 0x00006cfe CFDictionaryCreate + 58
6 CoreFoundation 0x00033d7c -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 1456
7 CoreFoundation 0x000361bc -[NSDictionary initWithObjectsAndKeys:] + 776
8 iota 0x0000c4cc 0x1000 + 46284
9 iota 0x00009282 0x1000 + 33410
10 iota 0x0000952a 0x1000 + 34090
11 Foundation 0x00015432 _nsnote_callback + 150
12 CoreFoundation 0x000271da __CFXNotificationPost_old + 390
13 CoreFoundation 0x00026e7a _CFXNotificationPostNotification + 122
14 Foundation 0x0000b9f6 -[NSNotificationCenter postNotification:] + 138
15 Foundation 0x0007ae02 postQueueNotifications + 258
16 Foundation 0x0007afae __NSPostIdleQueueNotes + 6
17 CoreFoundation 0x00031084 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
18 CoreFoundation 0x00030eb2 __CFRunLoopDoObservers + 494
19 CoreFoundation 0x00028206 __CFRunLoopRun + 934
20 CoreFoundation 0x00027d74 CFRunLoopRunSpecific + 220
21 CoreFoundation 0x00027c82 CFRunLoopRunInMode + 54
22 GraphicsServices 0x00004e84 GSEventRunModal + 188
23 UIKit 0x00004f8c -[UIApplication _run] + 564
24 UIKit 0x000024cc UIApplicationMain + 964
25 iota 0x0000533a 0x1000 + 17210
26 iota 0x000052fc 0x1000 + 17148
NSDictionary *contactNameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:item, #"contact", sortName, #"contactSortName", compositeName, #"compositeName", nil];
The crashes are random. Like it happens once in 15 trials of a particular action.
KERN_PROTECTION_FAILURE - means that your program is accessing a shared memory that it didn't have access to. That's why kenel sent killed your process. I'm pretty sure that some of your pointers point to wrong location. E.g.
NSObject* obj;
obj would have garbage as it's value. You have to declare it like this:
NSObject* obj = nil;
Without more info, it's hard to say. Usually it's because you try to access/insert into your dictionary an object that doesn't exist anymore.
Check if you're not inserting something that is not an instance of NSObject, like an int or something.
Given that you are using initWithObjectsAndKeys:, make sure that you have nil-terminated the list of arguments, as that's a common mistake that can lead to crashes.