drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

Exception within CDERevisionSet #159

Closed mwaterfall closed 10 years ago

mwaterfall commented 10 years ago

I've had 2 Ensembles crash reports come through over the past couple of weeks, thought I'd throw them over to you. Any ideas why this might be happening? Thanks.

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'

Last Exception Backtrace:
0   CoreFoundation                       0x00007fff9558e244 __exceptionPreprocess + 148
1   libobjc.A.dylib                      0x00007fff88144e75 objc_exception_throw + 43
2   CoreFoundation                       0x00007fff954892de -[__NSDictionaryM setObject:forKey:] + 1102
3   Ensembles                            0x000000010078a693 -[CDERevisionSet addRevision:] (CDERevisionSet.m:52)
4   Ensembles                            0x0000000100782112 -[CDEStoreModificationEvent revisionSet] (CDEStoreModificationEvent.m:50)
5   Ensembles                            0x0000000100771280 __55-[CDEEventBuilder makeNewEventOfType:uniqueIdentifier:]_block_invoke (CDEEventBuilder.m:89)
6   CoreData                             0x00007fff923e9cfe developerSubmittedBlockToNSManagedObjectContextPerform + 94
7   CoreData                             0x00007fff923e9c54 -[NSManagedObjectContext performBlockAndWait:] + 132
8   Ensembles                            0x0000000100770e88 -[CDEEventBuilder makeNewEventOfType:uniqueIdentifier:] (CDEEventBuilder.m:54)
9   Ensembles                            0x00000001007af6d7 __80-[CDESaveMonitor asynchronouslyStoreChangesForContext:changedObjectsDictionary:]_block_invoke (CDESaveMonitor.m:206)
10  CoreData                             0x00007fff9241a781 developerSubmittedBlockToNSManagedObjectContextPerform_privateasync + 81
11  libdispatch.dylib                    0x00007fff8e30028d _dispatch_client_callout + 8
12  libdispatch.dylib                    0x00007fff8e302673 _dispatch_queue_drain + 451
13  libdispatch.dylib                    0x00007fff8e3039c1 _dispatch_queue_invoke + 110
14  libdispatch.dylib                    0x00007fff8e301f87 _dispatch_root_queue_drain + 75
15  libdispatch.dylib                    0x00007fff8e303177 _dispatch_worker_thread2 + 40
16  libsystem_pthread.dylib              0x00007fff91482ef8 _pthread_wqthread + 314
17  libsystem_pthread.dylib              0x00007fff91485fb9 start_wqthread + 13
drewmccormack commented 10 years ago

I don't really know how this would arise. Are you making sure you cleanly terminate the app? You should make sure all sync activity is finished before allowing the app to terminate. You can do that by doing a merge when quitting, or using the processPendingChanges... method.

So, you would do your normal save, then you would do a merge/process after that to make sure everything is finished before allowing the app to terminate.

I have added an extra check in there so that at least there should not be a crash, but I suspect the crash may be a symptom of not cleanly terminating. (I guess maybe a save during a deleech might also cause something like this.)