Roobiq / RBQFetchedResultsController

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

getting odd crash when updating objects from a webservice #84

Closed skydivedan closed 8 years ago

skydivedan commented 8 years ago

Using RBQFetchedResultsController 4.0 Using RealmSwift 0.99.1

OK, I'm running a query, and getting a Results of "Item" objects. The initial results has no objects in it. This is a first-time run, on an empty database.

Next, I make a call to an external webservice, and I create "Item" objects, from a JSON array that I get back. The results update, and I see the results. So far so good.

I make another call to my webservice. Essentially getting back the exact same list of objects. Those get created in the same way, like this:

try realm.write({ () -> Void in
    // add/update the new items.
    realm.add(items, update: true)
})                        

Except this time, deep in the notification-update block, an exception is thrown.

@throw RLMException(@"Object type '%@' not persisted in Realm", className);

This gets here from createChangeSetsWithAddedSafeObjects, which loops through the list of changedObjects calling this:

     RLMObject *object = [RBQSafeRealmObject objectfromSafeObject:safeObject];

The className (referenced in the exception) is nil by the way -- unless there's some bad reporting with my debugger. I don't really know what else to do here. This was all working quite well before updating to 0.99.1 of RealmSwift.

Thanks for any advice you can provide.

bigfish24 commented 8 years ago

Interesting, let me see if I can reproduce with the demo project, but might need you to share some code (out of band if necessary).

thonydam commented 8 years ago

I also updated to 4.0 and seeing the same crash.

bigfish24 commented 8 years ago

Only with 0.99.1?

thonydam commented 8 years ago

I have seen the crash using realm 0.99.0 and 0.99.1 The CPU spike up to 100% and then crash in RBQFetchedResultController at registerChangeNotification: dispatch_semaphore_signal(sem);

bigfish24 commented 8 years ago

I found the issue, submitting fix

thonydam commented 8 years ago

Awesome! thank you

skydivedan commented 8 years ago

ugh, off-by-one errors. Thanks for the fast response, most appreciated.

bigfish24 commented 8 years ago

Will try to fix today sorry this wasn't smooth roll out