Roobiq / RBQFetchedResultsController

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

Fix crashes when moving objects between sections #97

Open ngs opened 8 years ago

ngs commented 8 years ago

Hi,

As I reported in #96 , there was a bug with moving objects between sections.

This pull request fixes #96

bigfish24 commented 8 years ago

@ngs the ObjC example project has a number of tests in it. Can you create a test that demonstrates the failure and shows this fixing it?

AndrewHartAR commented 8 years ago

I've been experiencing a crash recently on the line with the error message "Attemting to insert at index beyond bounds", and this pull request fixes it.

My situation is fairly niche: My Realm database is for storing the Messages, Conversations and Users for a messaging app. The first screen lists all the conversations. When cellForRowAtIndexPath is called, in a background thread I add a manager for that particular conversation, so it's cached for when the user taps the cell, so the conversation can be shown quicker. That manager has it's own RBQFetchedResultsController, and on the line performFetch is where this crash happens.

The crash happens in a specific situation though - it's when I log the user log, deleting all of their messages, and then log them back in. Upon logging them back in, it shows a cell for that conversation, which creates the conversation controller, which calls performFetch and crashes.

I don't entirely understand why this crash happens, but I implemented this pull request, and it fixes it. To make sure, I added a breakpoint inside the if statement, and sure enough, when it would have crashed, instead it continued fine.

Right now I'm implementing it as a manual change in my code, but I'd urge you to accept this pull request as it fixes my problem.