realm-core
realm-core copied to clipboard
Object has been deleted or invalidated.
SDK and version
SDK : Swift Version: Realm: 10.28.6 RealmDatabase: 12.5.1
App crashes when this code runs.
let realm = try Realm()
let fetchResult = realm.objects(HLAsset.self).filter("assetCollection=%@", hlAssetCollection)
for i in 0 ..< fetchResult!.count {
print(fetchResult![i].identifier) // => crash (not crashed for all object. explained below)
}
App was working well (database was OK). Added some objects to database. (nothing special) Exited an app. App runs => crash



You can see something is wrong with this screenshot. When I open the realm file with Realm Studio, there are objects have same identifier(Primary Key). I don't know how this can happen. When reading other objects, there is no problem. But when reading objects like this (some objects have same identifier), app crashes.

When I tried to save data as JSON, it failed. When I tried to save data as Local Realm, it saved .realm file(size changed from 167.1MB to 23.1MB) but it is not opened with Realm Studio nor an app.
I can confirm I have seen this kind of crash-report in a similar use-case as well.
Transferring to realm-swift as this seem to be happening above the Core line.
I'm not sure this is true, @jedelbo. I have seen this kind of crash/report also on Android and traced it down to lines that basically did nothing more than shown in this report.
@xiles Can you reduce this issue into a small sample app that reproduces the crash?
@leemaguire I sent an email to [email protected] with a broken database file. I cannot make a sample app to break a database file.. I don't know why and when it happened. But if you open a broken database file then select several objects has same identifier(Primary Key) and delete, Realm Studio says "Object is invalid. Either it has been previously deleted or the Realm it belongs to has been closed.”
We will investigate why such a scenario occurs.
@leemaguire I can investigate.
The database has some references pointing in the wrong direction. So it is clearly broken. I will take the issue back to core and make some further analysis on the file.
Why got this issue closed? It's analysed, but not fixed.
@BlueCobold Thanks for mentioning! Something got messed up when the issue was transferred from the Swift Repo.
Internal note: The database has invalid entries in the following clusters: [1, 2, 2, 4, 204] [1, 2, 2, 4, 206] [1, 2, 2, 4, 207] The keys array at [1,2,2,4] is also invalid.
@bmunkholm Can you tell which realm swift version fixes the issue?
@keerthika-priya It's not released yet. The fix/pr is in realm-core 12.12.0, which is not yet included in a released realm-swift version: https://github.com/realm/realm-swift/blob/master/CHANGELOG.md
@bmunkholm , @dianaafanador3 Do you know when the release can be expected for this issue?
@keerthika-priya No. I'm not working for Realm/Mongo and I'm waiting for that release myself.
@BlueCobold @BlueCobold We sure gonna do a release next week.
@dianaafanador3 any updates regarding the release?
@BlueCobold @keerthika-priya Version v10.33.0 https://github.com/realm/realm-swift/releases/tag/v10.33.0 has been released with the fix
Has the new release fixed the issue for everyone? Does it require any additional steps to stop the crashing?