RxSwiftCommunity / RxRealm

RxSwift extension for RealmSwift's types
MIT License
1.15k stars 265 forks source link

Crashes at 'bool read_only() const { return schema_mode == SchemaMode::ReadOnly; }' #64

Closed theoks closed 7 years ago

theoks commented 7 years ago

I have this object:

let territory = RoadObject()

which has this LinkingObjects property:

let roadNumbers = LinkingObjects.init(fromType: RoadNumberObject.self, property: "territory")

I create at my ViewModel this property to get an array with the linking objects:

let roadNumbers: Variable<[RoadNumberObject]>

I initialize it (by creating an Array from the LinkingObjects property):

self.roadNumbers = Variable(self.territory.roadNumbers.toArray())

And I am trying to bind an Observer from the LinkingObjects so I can track the changes and access them easily through the Variable (I am using the same realm everywhere by the way, and I do not access it in this case from a thread other than the Main one) :

Observable.array(from: self.territory.roadNumbers)
            .bindTo(roadNumbers)
            .disposed(by: disposeBag)

As soon as my ViewModel is initialized it crashes. I back traced the issue and the problem arises when I try to bind. I checked it as an Observable (not a Variable) and it doesn't crash, but I would like to use the variable for convenience.

The line where it crashes is:

bool read_only() const { return schema_mode == SchemaMode::ReadOnly; }

in the Config method in the shared_realm.hpp file

It doesn't happen though with a ReplaySubject, or a PublishSubject. Only with a Variable and a BehaviorSubject

It also doesn't happen if I initialize the Variable with an empty array (Variable([])). It only happens when it is already initialized as Variable(self.territory.roadNumbers.toArray())

One solution I found is if I initialize the Variable with an empty array and on the subscription I place .startWith(self.territory.roadNumbers.toArray())

icanzilb commented 7 years ago

This is most probably not on RxRealm's side, since the exception raises in the C++ code of the Realm core, but it's an interesting error - I'll try replicating it this week and help.

theoks commented 7 years ago

Should I post it on realm-cocoa repo too along with the similar issue I posted on stackoverflow?

icanzilb commented 7 years ago

@tkallioras it's probably worth reposting on Realm's github, especially if you have code how to replicate the crash and the full exception message. Somebody could rather quickly see what the reason for the issue is.

icanzilb commented 7 years ago

I see this is tracked by the realm cocoa team now: https://github.com/realm/realm-cocoa/issues/4731 . Closing this one down