Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when looping through RLMResults #6241

Closed
MV-EricDeHaan opened this issue Sep 5, 2019 · 8 comments
Closed

Crash when looping through RLMResults #6241

MV-EricDeHaan opened this issue Sep 5, 2019 · 8 comments

Comments

@MV-EricDeHaan
Copy link

MV-EricDeHaan commented Sep 5, 2019

Goals

Looping through objects in RLMResults

Expected Results

Enumeration of realm objects

Actual Results

Sometimes it does enumerate but sometimes it crashes...

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x0000000188f9ef0c libsystem_pthread.dylib`pthread_mutex_lock$VARIANT$mp
    frame #1: 0x000000010135f510 MVAnalyticsSDK`realm::SharedGroup::do_open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, bool, realm::SharedGroupOptions) + 2804
  * frame #2: 0x000000010128cd9c MVAnalyticsSDK`realm::SharedGroup::open(this=0x000000010496fc00, repl=<unavailable>, options=const realm::SharedGroupOptions @ 0x000000016f52e8f0) at group_shared.hpp:863:5 [opt]
    frame #3: 0x000000010128ca38 MVAnalyticsSDK`realm::SharedGroup::SharedGroup(this=0x000000010496fc00, repl=0x000000028392ae80, options=const realm::SharedGroupOptions @ 0x000000016f52eaf0) at group_shared.hpp:836:5 [opt]
    frame #4: 0x00000001012860f8 MVAnalyticsSDK`realm::Realm::open_with_config(realm::Realm::Config const&, std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication> >&, std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> >&, std::__1::unique_ptr<realm::Group, std::__1::default_delete<realm::Group> >&, realm::Realm*) [inlined] realm::SharedGroup::SharedGroup(this=<unavailable>, repl=<unavailable>) at group_shared.hpp:835:1 [opt]
    frame #5: 0x00000001012860e8 MVAnalyticsSDK`realm::Realm::open_with_config(realm::Realm::Config const&, std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication> >&, std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> >&, std::__1::unique_ptr<realm::Group, std::__1::default_delete<realm::Group> >&, realm::Realm*) [inlined] std::__1::__unique_if<realm::SharedGroup>::__unique_single std::__1::make_unique<realm::SharedGroup, realm::Replication&, realm::SharedGroupOptions&>(__args=0x000000028392ae80) at memory:3128 [opt]
    frame #6: 0x00000001012860a4 MVAnalyticsSDK`realm::Realm::open_with_config(config=<unavailable>, history=<unavailable>, shared_group=<unavailable>, read_only_group=<unavailable>, realm=<unavailable>) at shared_realm.cpp:196 [opt]
    frame #7: 0x00000001011bfc54 MVAnalyticsSDK`realm::_impl::RealmCoordinator::pin_version(this=<unavailable>, versionid=<unavailable>) at realm_coordinator.cpp:458:13 [opt]
    frame #8: 0x00000001011bfd40 MVAnalyticsSDK`realm::_impl::RealmCoordinator::register_notifier(notifier=std::__1::shared_ptr<realm::_impl::CollectionNotifier>::element_type @ 0x00000001099932c8 strong=2 weak=1) at realm_coordinator.cpp:490:14 [opt]
    frame #9: 0x00000001011c8d6c MVAnalyticsSDK`realm::Results::prepare_async(this=0x000000010997bd28, force=<unavailable>) at results.cpp:732:5 [opt]
    frame #10: 0x00000001011c5954 MVAnalyticsSDK`realm::Results::evaluate_query_if_needed(this=0x000000010997bd28, wants_notifications=true) at results.cpp:268:17 [opt]
    frame #11: 0x00000001011c568c MVAnalyticsSDK`realm::util::Optional<realm::BasicRowExpr<realm::Table> > realm::Results::try_get<realm::BasicRowExpr<realm::Table> >(this=0x000000010997bd28, row_ndx=0) at results.cpp:203:13 [opt]
    frame #12: 0x00000001011c5564 MVAnalyticsSDK`realm::BasicRowExpr<realm::Table> realm::Results::get<realm::BasicRowExpr<realm::Table> >(this=0x000000010997bd28, row_ndx=0) at results.cpp:216:20 [opt]
    frame #13: 0x0000000101a941dc VerusSDK`RLMAccessorContext auto realm::Results::get<RLMAccessorContext>(this=0x000000016f52f080, t=0x0000000000000000)::'lambda'(RLMAccessorContext&)::operator()<realm::BasicRowExpr<realm::Table>*>(RLMAccessorContext&) const at results.hpp:306:56
    frame #14: 0x0000000101a93c28 VerusSDK`RLMAccessorContext realm::switch_on_type<auto realm::Results::get<RLMAccessorContext>(RLMAccessorContext&, unsigned long)::'lambda'(RLMAccessorContext&)>(type=Object, fn=0x000000016f52f080) at property.hpp:171:33
    frame #15: 0x0000000101a93794 VerusSDK`RLMAccessorContext realm::Results::dispatch<auto realm::Results::get<RLMAccessorContext>(RLMAccessorContext&, unsigned long)::'lambda'(RLMAccessorContext&)>(this=0x000000010997bd28, fn=0x000000016f52f080) const at results.hpp:300:12
    frame #16: 0x0000000101a8f338 VerusSDK`auto realm::Results::get<RLMAccessorContext>(this=0x000000010997bd28, ctx=0x000000016f52f370, row_ndx=0) at results.hpp:306:12
    frame #17: 0x0000000101a8f0d8 VerusSDK`::-[RLMFastEnumerator countByEnumeratingWithState:count:](self=0x000000010995aab0, _cmd="countByEnumeratingWithState:count:", state=0x000000016f52f528, len=16) at RLMCollection.mm:129:51
    frame #18: 0x0000000101a8f584 VerusSDK`RLMFastEnumerate(state=0x000000016f52f528, len=16, collection=0x000000010997bd20) at RLMCollection.mm:167:12
    frame #19: 0x0000000101bc7054 VerusSDK`::-[RLMResults countByEnumeratingWithState:objects:count:](self=0x000000010997bd20, _cmd="countByEnumeratingWithState:objects:count:", state=0x000000016f52f528, buffer=0x000000016f52f598, len=16) at RLMResults.mm:181:12
    frame #20: 0x0000000101912b28 VerusSDK`-[ApiManager getScannedProducts](self=0x00000002819c8880, _cmd="getScannedProducts") at ApiManager.m:1154:5
    frame #21: 0x00000001019220e0 VerusSDK`-[VerusManager getScannedProducts](self=0x0000000283049600, _cmd="getScannedProducts") at VerusManager.m:893:12
    frame #22: 0x00000001008e7e54 Verus (int)`ScansTableViewController.showData(self=0x000000010449e430) at ScansTableViewController.swift:176:47
    frame #23: 0x00000001008de63c Verus (int)`MVViewController.viewWillAppear(animated=true, self=0x000000010449e430) at MVViewController.swift:39:9
    frame #24: 0x00000001008de69c Verus (int)`@objc MVViewController.viewWillAppear(_:) at <compiler-generated>:0
    frame #25: 0x00000001008e0ff0 Verus (int)`ScansTableViewController.viewWillAppear(animated=true, self=0x000000010449e430) at ScansTableViewController.swift:39:15
    frame #26: 0x00000001008e10bc Verus (int)`@objc ScansTableViewController.viewWillAppear(_:) at <compiler-generated>:0
    frame #27: 0x00000001b56ed940 UIKitCore`-[UIViewController _setViewAppearState:isAnimating:] + 584
    frame #28: 0x00000001b56ee00c UIKitCore`-[UIViewController __viewWillAppear:] + 140
    frame #29: 0x00000001b56457d4 UIKitCore`-[UINavigationController _startCustomTransition:] + 1248
    frame #30: 0x00000001b5659714 UIKitCore`-[UINavigationController _startDeferredTransitionIfNeeded:] + 708
    frame #31: 0x00000001b565ab3c UIKitCore`-[UINavigationController __viewWillLayoutSubviews] + 164
    frame #32: 0x00000001b563dd4c UIKitCore`-[UILayoutContainerView layoutSubviews] + 224
    frame #33: 0x00000001b6129170 UIKitCore`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1292
    frame #34: 0x000000018d8c3c60 QuartzCore`-[CALayer layoutSublayers] + 184
    frame #35: 0x000000018d8c8c08 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 332
    frame #36: 0x000000018d82b3e4 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 348
    frame #37: 0x000000018d859620 QuartzCore`CA::Transaction::commit() + 640
    frame #38: 0x000000018d85a15c QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
    frame #39: 0x0000000189317d08 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
    frame #40: 0x0000000189312a30 CoreFoundation`__CFRunLoopDoObservers + 412
    frame #41: 0x0000000189312fac CoreFoundation`__CFRunLoopRun + 1228
    frame #42: 0x00000001893127c0 CoreFoundation`CFRunLoopRunSpecific + 436
    frame #43: 0x000000018b51379c GraphicsServices`GSEventRunModal + 104
    frame #44: 0x00000001b5c91c38 UIKitCore`UIApplicationMain + 212
    frame #45: 0x000000010091e864 Verus (int)`main at AppDelegate.swift:15:7
    frame #46: 0x0000000188dd68e0 libdyld.dylib`start + 4

Steps to Reproduce

Code Sample

    RLMRealm *realm = [RLMRealm realmWithConfiguration:sharedInstance.realmConfiguration error:NULL];
    RLMResults<ScannedProduct *> *rlmScanned = [[ScannedProduct allObjectsInRealm:realm] sortedResultsUsingKeyPath:@"scannedAt" ascending:NO];
    NSLog(@"#scanned: %lu", (unsigned long)rlmScanned.count);
    
    NSMutableArray *result = [[NSMutableArray alloc] init];
    for (ScannedProduct *rlmScannedProduct in rlmScanned) {
        MVScannedProduct *scannedProduct = [sharedInstance getMVScannedProduct:rlmScannedProduct];
        
        [result addObject:scannedProduct];
    }
    return result;

Version of Realm and Tooling

Realm framework version: 3.14.1

Realm Object Server version: ?

Xcode version: 10.3

iOS/OSX version: 12.3

Dependency manager + version: ?

@bmunkholm
Copy link
Contributor

Can you reproduce it (perhaps unreliable)? How and where do you do that? How frequently does it happen?

@MV-EricDeHaan
Copy link
Author

In my app I can reproduce it. I have a ViewController with a tableview that shows data I retrieve from a Realm. That viewcontroller is one of the first I show. When I navigate from that viewcontroller to another viewcontroller and navigate back than in the viewWillAppear I try to retrieve the data (again) that is the moment the crash appears. I can get the count from the RLMResults and ik gives me the correct number of objects, but the moment I enter the for loop it results in a crash.

@bmunkholm
Copy link
Contributor

So you can reliably reproduce this - is it every single time?
Is it on a device, or the emulator?
Can you try to reduce the issue down to a self contained minimal repro project? (often that helps to debug it)

@MV-EricDeHaan
Copy link
Author

(Un)fortunately I can reliably reproduce this. It is on a device.
I have a, for me, complex situation. I build a framework that uses Realm. When I use that framework in the mentioned app the crash happens. When I add a target in my framework project that uses the framework, I sometimes can reproduce the issue. But that is not reliable, it occurs occasionally...

@bmunkholm
Copy link
Contributor

Well, "if we can reproduce it we can fix it" :-).
Does the same happen in a simulator?
Would it be possible to share the app and framework with us?

@MV-EricDeHaan
Copy link
Author

I second your first statement ;-)
The app uses the camera for scanning (Vuforia and Digimarc) so the simulator does not work.
I can share my project, but my manager and CEO are a bit more reserved…

What is the best way to share? A zip over WeTransfer and a password via email?

@realm realm deleted a comment from MV-EricDeHaan Sep 5, 2019
@bmunkholm
Copy link
Contributor

@MV-EricDeHaan You can create a private issue at support.realm.io and share the password there. Reference this github issue.
Ideally try to reduce the scope/dependencies of the app.
Also include full instructions on how to reproduce.

@tgoyne Can you see anything obvious here?

@bmunkholm
Copy link
Contributor

For internal reference to the app sent in to support: https://support.realm.io/a/tickets/4694.

@tgoyne tgoyne closed this as completed Sep 18, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants