JohnEstropia / CoreStore

Unleashing the real power of Core Data with the elegance and safety of Swift
MIT License
3.99k stars 255 forks source link

EXC_BAD_ACCESS (code=1, address=0x0) on modern apple devices #291

Open alabash opened 5 years ago

alabash commented 5 years ago

Hi!

I'm using your library in several projects and love it. It works great and the problem seems to occur only on new Apple devices which is a mystery for me. And only in development (release build configuration crashes too) while simple Adhoc or Testflight install works fine, like it never happened. I've tested on iPhone XR and iPhone XS Max, they both crash while iPad Air, iPad Air 2 and iPad Mini 2 work as expected. All the devices mentioned above are running under iOS 12.1.

I've isolated crashing code. It is pretty straightforward.

class User: CoreStoreObject {
    let userId = Value.Required<Int>("user_id", initial: 0)
    let name = Value.Optional<String>("name")
}

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let dataStack = DataStack(
            CoreStoreSchema(
                modelVersion: "V1",
                entities: [
                    Entity<User>("User")
                ],
                versionLock: [
                    "User": [0x71f1c9576306cae1, 0x1cc9e7d27b8905bd, 0x90ecdf3454c60c44, 0xe4f0004dd40736de]
                ]
            )
        )

        do {
            try dataStack.addStorageAndWait(SQLiteStore(fileName: "DataStorage.sqlite", localStorageOptions: .recreateStoreOnModelMismatch))
        } catch {
            print(error.localizedDescription)
        }

        CoreStore.defaultStack = dataStack

        CoreStore.perform(
            asynchronous: { transaction in
                let user: User = transaction.create(Into<User>())
                user.userId .= 1
                user.name .= "Core Store"
            },
            success: { _ in

            },
            failure: { error in
                print(error.localizedDescription)
            }
        )
    }
}

image

Can you help? :)

JohnEstropia commented 5 years ago

There's nothing that particularly stands out in your code and your screenshot so I'm not sure what's going on. By any chance, is your project's SWIFT_REFLECTION_METADATA_LEVEL Build Setting set to anything than All? Also, how are you importing Corestore, by Pod or through Carthage?

alabash commented 5 years ago

Thanks for the response. No, I didn't change it. Just checked it now it is set to "All". I'm using cocoapods.

JohnEstropia commented 5 years ago

Hmm.. Does it happen to the mentioned devices on simulator as well?

alabash commented 5 years ago

No, on the simulator it works ok, no crashes.

JohnEstropia commented 5 years ago

@evilgeniuz I recently bumped the Minimum Deployment Version in the develop branch. Can you try pointing your Pod to that branch and see if the behavior changes? (I am assuming your app is at iOS 10+ as minimum deployment version, though)

alabash commented 5 years ago

Unfortunately the same. Gives error on XR and no errors on iPad mini 2.

JohnEstropia commented 5 years ago

I've reproduced the issue using the CoreStoreDemo app. It looks like this issue was first in Xcode 10.1: https://github.com/wordpress-mobile/WordPress-iOS/issues/10389

Still investigating...

JohnEstropia commented 5 years ago

@evilgeniuz Do you have a released version of the app built with Xcode 10.1? Do you see these crashes there?

alabash commented 5 years ago

Yeah, just checked it, crashes in 10.1 and in 10.0 works ok.

JohnEstropia commented 5 years ago

Looks like we'll just have to wait for an update or use Xcode 10.0 for now. Related issues: https://github.com/realm/realm-cocoa/issues/6013 https://github.com/wordpress-mobile/WordPress-iOS/pull/10400

alabash commented 5 years ago

Yeah, using 10.0 for now everywhere. ありがとう!

Miggets7 commented 5 years ago

Have the same issue, only when using a physical device in debugging mode. Even on a iPhone 5s. Thought to just mention it.