【问题标题】:Corrupt pointer when using Realm in iOS app after upgrading from Xcode 9.4 to Xcode 11 and Swift 3.0 to Swift 4.2从 Xcode 9.4 升级到 Xcode 11 和从 Swift 3.0 升级到 Swift 4.2 后在 iOS 应用程序中使用 Realm 时指针损坏
【发布时间】:2019-09-12 07:14:43
【问题描述】:

我有一个包含 Swift 和 Objective-C 代码的混合应用程序。在 Xcode 9.4 中运行代码时没有问题。升级到 Xcode 11(加上请求升级到 Swift 4.2)后,应用程序在尝试引用 Realm 0.93.2 库中已释放的实例时崩溃并出现 EXC_BAD_ACCESS 错误。

以下是事件的顺序:

  1. 启动:

        @UIApplicationMain
    class VGPAppDelegate: UIResponder, UIApplicationDelegate, BITCrashManagerDelegate, BITHockeyManagerDelegate {

        var window: UIWindow?

        internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            //trigger the ui appearance
            VGPUIAppearance.triggerAppearance()

            //setup network monitoring
            TSReachabilityManager.default()
            //Update Realm Scheme
            VGPRealmMigrator.updateRealmSchema()

            setUpHockeyApp()
            setupAppearance()

            if didCrashInLastSessionOnStartup() {
                // Delay launch for sending the crash report
            } else {
                setupApplication()
            }

            return true
        }

  1. 在调用 VGPRealmMigrator.updateRealmSchema() 之后

    for (Class cls in s_localNameToClass.allValues) {
    RLMObjectSchema *schema = [RLMObjectSchema 
    schemaForObjectClass:cls];
    [schemaArray addObject:schema];

            // override sharedSchema classs methods for performance
            RLMReplaceSharedSchemaMethod(cls, schema);

            // set standalone class on shared shema for standalone object creation
            schema.standaloneClass = RLMStandaloneAccessorClassForObjectClass(schema.objectClass, schema);
        }
        free(classes);

注意:架构在 Realm > RLMSchema.mm > Intitialise 中有一个有效的指针

  1. 现在在 Realm > RLMAccessor.mm

    static Class RLMCreateAccessorClass(Class objectClass,
                                        RLMObjectSchema *schema,
                                        NSString *accessorClassPrefix,
                                        IMP (*getterGetter)(RLMProperty *, RLMAccessorCode, NSString *),
                                        IMP (*setterGetter)(RLMProperty *, RLMAccessorCode)) {
        // throw if no schema, prefix, or object class
        if (!objectClass || !schema || !accessorClassPrefix) {
            @throw RLMException(@"Missing arguments");
        }
        if (!RLMIsKindOfClass(objectClass, RLMObjectBase.class)) {
            @throw RLMException(@"objectClass must derive from RLMObject or Object");
        }

        // create and register proxy class which derives from object class
        NSString *accessorClassName = [accessorClassPrefix stringByAppendingString:schema.className];
        Class accClass = objc_getClass(accessorClassName.UTF8String);
        if (!accClass) {
            accClass = objc_allocateClassPair(objectClass, accessorClassName.UTF8String, 0);
            objc_registerClassPair(accClass);
        }


应用程序在包含引用 schema.className 的语句中崩溃。这里模式有空指针。 Zombie 显示“消息已发送到已释放的实例”。

【问题讨论】:

    标签: ios swift xcode realm


    【解决方案1】:

    我使用的是 Realm 的一个古老版本 (0.93.2)。通过以下方式解决了问题:

    1. pod install --repo-update
    2. pod install(这给了我最新版本,即 3.17.3)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 2018-05-31
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      相关资源
      最近更新 更多