Open jadar opened 2 years ago
I've managed to recreate the issue in a new project. Here is a link to the repo. https://github.com/jadar/RealmNotificationIssue
Once you launch the app, follow these steps to reproduce.
Thanks for the repro case! I think I see what the problem is. We don't handle the pattern "remove last observer from collection -> perform a write which modifies the collection -> add a new observer to the collection" correctly. We skip doing the changeset calculation for the collection while it doesn't have any observers, but don't fully revert into the state we had before the first observer was added, and so the first changeset calculated after adding an observer again is wrong.
This should be fairly easy to fix, and you can work around it for now by moving collection = realm.objects(Animal.self)
from viewDidLoad()
to viewWillAppear()
so that you aren't observing a previously-but-no-longer-observed collection on the second appearance of the view.
Thanks, that solution worked! It would be nice to keep using the same collection, but I suppose that is a reasonable workaround. I use that pattern all across my codebase and also keep seeing these crashes in Sentry. Perhaps this isn't the only area that it's happening.
Recently I updated to a recent version of Realm (v10.35.0) and this seems still to be happening.
@jadar did you figure this out?
How frequently does the bug occur?
All the time
Description
I've been trying to debug a UITableView crash where there is an inconsistent number of rows. I can consistently cause this after the entities that were previously displayed are all deleted in another view. When the list view appears, a change listener is created for a
Results
collection. The.initial
update is delivered, and the count is zero. Soon after (though I'm not sure if in the same run-loop or not,) an update is delivered with 1 deletion of row 0. However, I can confirm in the debugger that the collection had zero rows before the update. I'm confused why this update would be delivered if there was nothing there in the first place. I think I've ruled out programmer-errors on my side, so I'm pretty sure it's an issue in Realm's change notifications.Let me know if you need any more information.
Stacktrace & log output
Can you reproduce the bug?
Yes, always
Reproduction Steps
.initial
update, confirm thereRLMCollection.count
is 0..update
update with the deletion.Version
10.24.2, 10.25.1
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
iOS 15.4.1
Build environment
Xcode version: 13.3.0 Dependency manager and version: SPM