Realm-cocoa: EXC_BAD_ACCESS KERN_INVALID_ADDRESS for user updated from old schema to new sechama

Created on 29 Mar 2016  路  10Comments  路  Source: realm/realm-cocoa

This morning i have release a new version to app store and every existing users who updated to the latest version facing this crash.

Information:
Xcode: 7.3
Realm: 0.96.2
Previous schema version: 16.

I have included the migration block as below.

 RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    config.schemaVersion = 17;
    config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
        if (oldSchemaVersion < 17) {
//            self.isDatabaseVersionChanged = YES;
        }

Below is the Crashlytics report.

> Thread : Crashed: com.apple.main-thread
> 0  libobjc.A.dylib                0x1800b9bdc objc_msgSend + 28
> 1  Register                       0x1002b3960 -[RLMSchema setObjectSchema:] (RLMSchema.mm:100)
> 2  Register                       0x1002b41b0 +[RLMSchema dynamicSchemaFromRealm:] (RLMSchema.mm:210)
> 3  Register                       0x100247478 -[RLMMigration initWithRealm:key:error:] (RLMMigration.mm:62)
> 4  Register                       0x1002a7d9c __31-[RLMRealm migrationBlock:key:]_block_invoke (RLMRealm.mm:465)
> 5  Register                       0x100252ad0 std::__1::__function::__func<RLMUpdateRealmToSchemaVersion::$_0, std::__1::allocator<RLMUpdateRealmToSchemaVersion::$_0>, void (realm::Group*, std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >&)>::operator()(realm::Group*&&, std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >&) (RLMObjectStore.mm:164)
> 6  Register                       0x100232310 std::__1::function<void (realm::Group*, std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >&)>::operator()(realm::Group*, std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >&) const (functional:1817)
> 7  Register                       0x10022ecd4 realm::ObjectStore::update_realm_with_schema(realm::Group*, unsigned long long, std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >&, std::__1::function<void (realm::Group*, std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >&)>) (object_store.cpp:372)
> 8  Register                       0x10024fdc8 RLMUpdateRealmToSchemaVersion (RLMObjectStore.mm:161)
> 9  Register                       0x1002a7754 +[RLMRealm realmWithConfiguration:error:] (RLMRealm.mm:431)
> 10 Register                       0x1002a6d38 +[RLMRealm defaultRealm] (RLMRealm.mm:306)
> 11 Register                       0x100248b4c +[RLMObject objectsWithPredicate:] (RLMObject.mm:127)
> 12 Register                       0x100248908 +[RLMObject objectsWhere:args:] (RLMObject.mm:113)
> 13 Register                       0x100248884 +[RLMObject objectsWhere:] (RLMObject.mm:109)
> 14 Register                       0x1000fc8e8 -[OFModelManager(Store) fetchAllStoresInContextThatBelongsToUser] (OFModelManager+Store.m:118)
> 15 Register                       0x10010bc00 -[OFAppDelegate getRequest] (OFAppDelegate.m:162)
> 16 Register                       0x10010d620 -[OFAppDelegate startFetch] (OFAppDelegate.m:430)
> 17 Register                       0x10010c8bc -[OFAppDelegate application:didFinishLaunchingWithOptions:] (OFAppDelegate.m:290)
> 18 UIKit                          0x1857a1704 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400
> 19 UIKit                          0x1859d0130 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904
> 20 UIKit                          0x1859d44b8 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1672
> 21 UIKit                          0x1859d15c0 -[UIApplication workspaceDidEndTransaction:] + 168
> 22 FrontBoardServices             0x181fef790 -[FBSSerialQueue _performNext] + 184
> 23 FrontBoardServices             0x181fefb10 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
> 24 CoreFoundation                 0x1809f0efc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
> 25 CoreFoundation                 0x1809f0990 __CFRunLoopDoSources0 + 540
> 26 CoreFoundation                 0x1809ee690 __CFRunLoopRun + 724
> 27 CoreFoundation                 0x18091d680 CFRunLoopRunSpecific + 384
> 28 UIKit                          0x18579a580 -[UIApplication _run] + 460
> 29 UIKit                          0x185794d90 UIApplicationMain + 204
> 30 Register                       0x10013ce00 main (main.m:17)
> 31 libdispatch.dylib              0x1804be8b8 (Missing)

Does it has any issue regarding using the latest Xcode 7.3 to build and submit? Previously doesn't have these crashes. User need to delete app and reinstall to solve this issue.

T-Help

Most helpful comment

UPDATE:
1) This crash only happens on production build. I have tested via submit a build with Xcode 7.3 to test flight. It crashed when i update the app.
2) I have downgraded to Xcode 7.2.1 and submitted another build to test flight and it doesn't crash.

Above are what i found and tested. Feels like it is a issue in Xcode 7.3.

All 10 comments

UPDATE:
1) This crash only happens on production build. I have tested via submit a build with Xcode 7.3 to test flight. It crashed when i update the app.
2) I have downgraded to Xcode 7.2.1 and submitted another build to test flight and it doesn't crash.

Above are what i found and tested. Feels like it is a issue in Xcode 7.3.

@kokhong20

The crash on update the new scheme.

Invoked Realm API

RLMObjectSchema.mm

  • (realm::Table *)table
    _table = ObjectStore::table_for_object_type(_realm.group, _className.UTF8String

My solution:
get the table object before check the type of _className
if ([_className isKindOfClass:[NSString class]]) {
_table = ObjectStore::table_for_object_type(_realm.group, _className.UTF8String);
}

It's not the best solution , Waiting for the best answer.

Have you considered trying the most recent version of Realm to check whether the crash still occurs for you? Another user reported seeing the same sort of crash in #3398. Updating from v0.96.x to the most recent release addressed the crash for them.

@zhangzhang86 just asking, did you mark this key as Yes in Xcode 7.3?
image

Like kokhong92 said, I have same issue that didn't happen before when migration occurred. Due to app sizing issue, I still use 0.95.0. If this is Xcode 7.3 related issue, then I most likely need to downgrade to 7.2.1..

@bdash This issue solved by updating to the latest version 0.98.6. Just curious what is causing this issue and is only on production release.

@luohui8891
No.

Just asking, Are you from China ?

@zhangzhang86 yep.

Make sure to set Weak References in Manual Retain Release to YES in your Xcode project's configuration, and if you're still seeing this crash, we'll reopen this issue.

Had the same issues on production, this came up as an unpleasant surprise. How can I test so it doesn't work with new updated Realm?

I was specifically testing migration via test flight and it worked fine, but on production it dies.

Was this page helpful?
0 / 5 - 0 ratings