Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
477 stars 70 forks source link

Crash on `performFetch` - Index is out of bounds #104

Open AndrewHartAR opened 8 years ago

AndrewHartAR commented 8 years ago

I'm encountering a crash whenever my user logs in.

My model is made up of Messages, Conversations and Users. The first screen lists all conversations in a table view, and upon calling cellForRowAtIndexPath it creates a ConversationManager, which has its own RBQFetchedResultsController for listing messages inside of a conversation. This would have been done previously when the user tapped the cell, but it's done in cellForRow so that a number of them can be cached.

Upon having the first lot of messages added, which right now is for a single conversation in my testing, it initialises a ConversationManager, and crashes on performFetch. Here's the error I get in the console:

* Terminating app due to uncaught exception 'RLMException', reason: 'Index 5 is out of bounds (must be less than 5)' * First throw call stack: ( 0 CoreFoundation 0x00000001062bed85 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000105d32deb objc_exception_throw + 48 2 Realm 0x0000000103b6909b _ZL10throwErrorv + 379 3 Realm 0x0000000103b64ffa _ZL15translateErrorsIZ34-[RLMArrayLinkView objectAtIndex:]E3$3EDaOT + 58 4 Realm 0x0000000103b64fa2 -[RLMArrayLinkView objectAtIndex:] + 82 5 RBQFetchedResultsController 0x00000001039fe0cc -[RBQFetchedResultsController safeObjectsFromChanges:withCollection:isInsertion:] + 972 6 RBQFetchedResultsController 0x00000001039fefbb 58-[RBQFetchedResultsController registerChangeNotifications]_block_invoke_2.393 + 443 7 Realm 0x0000000103b7102c _ZZ23RLMAddNotificationBlockIN5realm7ResultsEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS5_P19RLMCollectionChangeP7NSErrorEbENUlRKNS0_19CollectionChangeSetESt13exception_ptrE_clESGSH + 620 8 Realm 0x0000000103b70d89 _ZNSt3128invoke_void_return_wrapperIvE6__callIJRZ23RLMAddNotificationBlockIN5realm7ResultsEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS9_P19RLMCollectionChangeP7NSErrorEbEUlRKNS4_19CollectionChangeSetESt13exception_ptrE_SI_SLEEEvDpOT + 153 9 Realm 0x0000000103b70b29 _ZNSt3110function6funcIZ23RLMAddNotificationBlockIN5realm7ResultsEEP20RLMNotificationTokenP11objc_objectRT_U13block_pointerFvS8_P19RLMCollectionChangeP7NSErrorEbEUlRKNS3_19CollectionChangeSetESt13exception_ptrE_NS_9allocatorISL_EEFvSH_SK_EEclEOSHOSK + 73 10 Realm 0x0000000103aaf0bc _ZNKSt318functionIFvN5realm19CollectionChangeSetESt13exception_ptrEEclES2S3 + 172 11 Realm 0x0000000103aac056 _ZN5realm5_impl18CollectionNotifier14call_callbacksEv + 198 12 Realm 0x0000000103b1aba7 _ZN5realm5_impl16RealmCoordinator16advance_to_readyERNS_5RealmE + 3079 13 Realm 0x0000000103cc92c9 _ZN5realm5Realm6notifyEv + 329 14 Realm 0x0000000103cf356f _ZZN5realm5_impl17WeakRealmNotifierC1ERKNSt3110shared_ptrINS_5RealmEEEbENK3$_0clEPv + 79 15 Realm 0x0000000103cf3518 _ZZN5realm5_impl17WeakRealmNotifierC1ERKNSt3__110shared_ptrINS_5RealmEEEbEN3$_08invokeEPv + 24 16 CoreFoundation 0x00000001061e4301 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 17 CoreFoundation 0x00000001061da1a7 CFRunLoopDoSources0 + 423 18 CoreFoundation 0x00000001061d96e3 CFRunLoopRun + 867 19 CoreFoundation 0x00000001061d90f8 CFRunLoopRunSpecific + 488 20 CoreFoundation 0x0000000106290501 CFRunLoopRun + 97 21 RBQFetchedResultsController 0x00000001039fe7e1 __58-[RBQFetchedResultsController registerChangeNotifications]_block_invoke + 193 22 libdispatch.dylib 0x000000010776fd9d _dispatch_call_block_and_release + 12 23 libdispatch.dylib 0x00000001077903eb _dispatch_client_callout + 8 24 libdispatch.dylib 0x0000000107778b2f _dispatch_root_queue_drain + 1829 25 libdispatch.dylib 0x0000000107778405 _dispatch_worker_thread3 + 111 26 libsystem_pthread.dylib 0x0000000107acd4de _pthread_wqthread + 1129 27 libsystem_pthread.dylib 0x0000000107acb341 start_wqthread + 13 ) libc++abi.dylib: terminating with uncaught exception of type NSException

I've also attached the stack traces (I don't know a better way to provide them, but it's reproducible so let me know if I can help any further).

screen shot 2016-07-07 at 11 34 12 screen shot 2016-07-07 at 11 33 58 screen shot 2016-07-07 at 11 33 26