Crash when looping through RLMResults


#1

I have the following code:

    RLMRealm *realm = [RLMRealm realmWithConfiguration:sharedInstance.realmConfiguration error:NULL];
    RLMResults *rlmScanned = [[ScannedProduct allObjectsInRealm:realm] sortedResultsUsingKeyPath:@"scannedAt" ascending:NO];
    NSLog(@"#scanned: %lu", (unsigned long)rlmScanned.count);
    
    for (ScannedProduct *rlmScannedProduct in rlmScanned) {
}

When I enter the for-loop my app crashes in

inline void SharedGroup::open(Replication& repl, const SharedGroupOptions options)
{
    // Exception safety: Since open() is called from constructors, if it throws,
    // it must leave the file closed.

    REALM_ASSERT(!is_attached());

    repl.initialize(*this); // Throws

    typedef _impl::GroupFriend gf;
    gf::set_replication(m_group, &repl);

    std::string file = repl.get_database_path();
    bool no_create = false;
    bool is_backend = false;
    do_open(file, no_create, is_backend, options); // Throws
}

on do_open with an EXC_BAD_ACCESS

Is there anyone who can tell me how I can prevent this?


#2

Hi Eric,
While the Forum is good for community questions and knowledge sharing, Github is better for bug reports and crashes. You should under normal circumstances not be able to crash.
So please create an issue in github.com/realm/realm-cocoa and include all details of the crash. Ideally if you can reduced your issue to a self contained minimal app we can better help.

Thanks