Roobiq / RBQFetchedResultsController

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

Crashes when moving objects between sections #96

Open ngs opened 8 years ago

ngs commented 8 years ago

Hi,

I'm experiencing crashes when I try to move objects between sections.

[before]
- section0
  - row0 (id=1)
  - row1 (id=2)
- section1
  - row0 (id=3)
  - row1 (id=4)

[after]
- section0
  - row0 (id=3)
  - row1 (id=4)
- section1
  - row0 (id=1)
  - row1 (id=2)

We can reproduce this crash using Swift-cocoapods example project in my fork https://github.com/ngs/RBQFetchedResultsController/commit/24b60cf3b06e9869b313d8d0898d968116e9c0f2

Stacktrace would be like:

* thread #3: tid = 0xad0b5a, 0x000000010d06fc6b libc++abi.dylib`__cxa_throw, queue = 'com.apple.root.user-initiated-qos', stop reason = breakpoint 3.2
    frame #0: 0x000000010d06fc6b libc++abi.dylib`__cxa_throw
    frame #1: 0x000000010926928d Realm`realm::List::verify_valid_row(this=0x00007ff4764d3838, row_ndx=0, insertion=false) const + 173 at list.cpp:61
    frame #2: 0x000000010926950f Realm`realm::List::get(this=0x00007ff4764d3838, row_ndx=0) const + 47 at list.cpp:95
    frame #3: 0x00000001092fc36f Realm`-[RLMArrayLinkView objectAtIndex:]::$_3::operator(this=0x0000700000091fa8)() const + 47 at RLMArrayLinkView.mm:222
    frame #4: 0x00000001092f8111 Realm`auto translateErrors<-[RLMArrayLinkView objectAtIndex:]::$_3>(f=0x0000700000091fa8) + 17 at RLMArrayLinkView.mm:113
    frame #5: 0x00000001092f80e2 Realm`-[RLMArrayLinkView objectAtIndex:](self=0x00007ff4764d3810, _cmd="objectAtIndex:", index=0) + 82 at RLMArrayLinkView.mm:222
  * frame #6: 0x00000001091d0bac RBQFetchedResultsController`-[RBQFetchedResultsController safeObjectsFromChanges:withCollection:isInsertion:](self=0x00007ff47441aeb0, _cmd="safeObjectsFromChanges:withCollection:isInsertion:", changes=@"1000 elements", collection=0x00007ff47177ee50, isInsertion=NO) + 972 at RBQFetchedResultsController.m:662
    frame #7: 0x00000001091d1a9b RBQFetchedResultsController`__58-[RBQFetchedResultsController registerChangeNotifications]_block_invoke_2.393(.block_descriptor=<unavailable>, collection=0x00007ff47177ee50, change=0x00007ff4764d8860, error=0x0000000000000000) + 443 at RBQFetchedResultsController.m:714
    frame #8: 0x000000010930470c Realm`RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(this=0x00007ff4764d76e8, changes=0x0000700000092580, err=(__ptr_ = 0x0000000000000000)) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)::operator()(realm::CollectionChangeSet const&, std::exception_ptr) + 620 at RLMCollection.mm:330
    frame #9: 0x0000000109304469 Realm`void std::__1::__invoke_void_return_wrapper<void>::__call<RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(objc_object*, realm::Results&, void (objc_object*, RLMCollectionChange*, NSError*) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)&, realm::CollectionChangeSet, std::exception_ptr>(RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(objc_object*, realm::Results&, void (objc_object*, RLMCollectionChange*, NSError*) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)&&&, realm::CollectionChangeSet&&, std::exception_ptr&&) [inlined] decltype(__f=0x00007ff4764d76e8, __args=0x0000700000092580, __args=0x0000700000092568)(std::__1::forward<realm::CollectionChangeSet, std::exception_ptr>(fp0))) std::__1::__invoke<RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(objc_object*, realm::Results&, void (objc_object*, RLMCollectionChange*, NSError*) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)&, realm::CollectionChangeSet, std::exception_ptr>(realm::Results&&, realm::CollectionChangeSet&&, std::exception_ptr&&) + 94 at __functional_base:416
    frame #10: 0x000000010930440b Realm`void std::__1::__invoke_void_return_wrapper<void>::__call<RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(__args=0x00007ff4764d76e8, __args=0x0000700000092580, __args=0x0000700000092568) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)&, realm::CollectionChangeSet, std::exception_ptr>(RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(objc_object*, realm::Results&, void (objc_object*, RLMCollectionChange*, NSError*) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)&&&, realm::CollectionChangeSet&&, std::exception_ptr&&) + 59 at __functional_base:468
    frame #11: 0x0000000109304209 Realm`std::__1::__function::__func<RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(objc_object*, realm::Results&, void (objc_object*, RLMCollectionChange*, NSError*) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr), std::__1::allocator<RLMNotificationToken* RLMAddNotificationBlock<realm::Results>(objc_object*, realm::Results&, void (objc_object*, RLMCollectionChange*, NSError*) block_pointer, bool)::'lambda'(realm::CollectionChangeSet const&, std::exception_ptr)>, void (realm::CollectionChangeSet, std::exception_ptr)>::operator(this=0x00007ff4764d76e0, __arg=0x0000700000092580, __arg=0x0000700000092568)(realm::CollectionChangeSet&&, std::exception_ptr&&) + 73 at functional:1437
    frame #12: 0x000000010923dc0c Realm`std::__1::function<void (realm::CollectionChangeSet, std::exception_ptr)>::operator(this=0x00007000000926c0, __arg=CollectionChangeSet @ 0x0000700000092580, __arg=(__ptr_ = 0x0000000000000000))(realm::CollectionChangeSet, std::exception_ptr) const + 172 at functional:1817
    frame #13: 0x000000010923aba6 Realm`realm::_impl::CollectionNotifier::call_callbacks(this=0x00007ff473830618) + 198 at collection_notifier.cpp:303
    frame #14: 0x00000001092af0c7 Realm`realm::_impl::RealmCoordinator::advance_to_ready(this=0x00007ff471609870, realm=0x00007ff47177f170) + 3079 at realm_coordinator.cpp:586
    frame #15: 0x000000010945e1c9 Realm`realm::Realm::notify(this=0x00007ff47177f170) + 329 at shared_realm.cpp:422
    frame #16: 0x000000010948825f Realm`realm::_impl::WeakRealmNotifier::WeakRealmNotifier(this=0x00000001094881f0, info=0x00007ff4714f9fe0)::$_0::operator()(void*) const + 79 at weak_realm_notifier.cpp:40
    frame #17: 0x0000000109488208 Realm`realm::_impl::WeakRealmNotifier::WeakRealmNotifier(info=0x00007ff4714f9fe0)::$_0::__invoke(void*) + 24 at weak_realm_notifier.cpp:38
    frame #18: 0x0000000109ad5301 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #19: 0x0000000109acb22c CoreFoundation`__CFRunLoopDoSources0 + 556
    frame #20: 0x0000000109aca6e3 CoreFoundation`__CFRunLoopRun + 867
    frame #21: 0x0000000109aca0f8 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #22: 0x0000000109b81501 CoreFoundation`CFRunLoopRun + 97
    frame #23: 0x00000001091d12c1 RBQFetchedResultsController`__58-[RBQFetchedResultsController registerChangeNotifications]_block_invoke(.block_descriptor=<unavailable>) + 193 at RBQFetchedResultsController.m:691
    frame #24: 0x000000010d153d9d libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #25: 0x000000010d1743eb libdispatch.dylib`_dispatch_client_callout + 8
    frame #26: 0x000000010d15cb2f libdispatch.dylib`_dispatch_root_queue_drain + 1829
    frame #27: 0x000000010d15c405 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #28: 0x000000010d4b14de libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #29: 0x000000010d4af341 libsystem_pthread.dylib`start_wqthread + 13

I'm working on fix this bug now, will send a PR later.

Thanks.