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

EXC_BAD_ACCESS on initialization #7

Closed
JerrySievert opened this issue Oct 2, 2015 · 9 comments
Closed

EXC_BAD_ACCESS on initialization #7

JerrySievert opened this issue Oct 2, 2015 · 9 comments
Labels

Comments

@JerrySievert
Copy link

in DatabaseQueue.init():

        try self.init(database: Database(path: path, configuration: configuration))

results in EXC_BAD_ACCESS (code=EXC_i386_GPFLT)

code in my ViewController looks like this:

class ViewController: UIViewController,CLLocationManagerDelegate {
    var dbQueue: AnyObject?
    override func viewDidLoad() {
        do {
            dbQueue = try DatabaseQueue(path: "/db.sqlite")
        } catch {
            print("Error opening SQLite Database")
        }

Any ideas on working around this?

@JerrySievert
Copy link
Author

this is Xcode 7 and Swift 2

@groue
Copy link
Owner

groue commented Oct 2, 2015

Weird. Do you have a stack trace?

@JerrySievert
Copy link
Author

Findme(24423,0x11222d300) malloc: *** error for object 0x7f9bce2c9060: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
(lldb) bt
* thread #1: tid = 0x1e8292, 0x000000011225f286 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x000000011225f286 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00000001122289f9 libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x0000000111fd0a44 libsystem_c.dylib`abort + 129
    frame #3: 0x00000001120eab92 libsystem_malloc.dylib`free + 425
  * frame #4: 0x000000010f163404 GRDB`GRDB.DatabaseQueue.init (path="/db.sqlite", configuration=GRDB.Configuration @ 0x00007fff50c99460, self=0x00007f9bce2c9060, $error=ErrorType @ 0x00007fff50c99898)(path : Swift.String, configuration : GRDB.Configuration) throws -> GRDB.DatabaseQueue + 996 at DatabaseQueue.swift:44
    frame #5: 0x000000010f163644 GRDB`GRDB.DatabaseQueue.__allocating_init (path="/db.sqlite", configuration=GRDB.Configuration @ 0x00007fff50c995d0, $metatype=GRDB.DatabaseQueue, $error=ErrorType @ 0x00007fff50c99898)(path : Swift.String, configuration : GRDB.Configuration) throws -> GRDB.DatabaseQueue + 532 at DatabaseQueue.swift:0
    frame #6: 0x000000010ef65718 Findme`Findme.ViewController.viewDidLoad (self=0x00007f9bcb5b8800)() -> () + 280 at ViewController.swift:47
    frame #7: 0x000000010ef66012 Findme`@objc Findme.ViewController.viewDidLoad (Findme.ViewController)() -> () + 34 at ViewController.swift:0
    frame #8: 0x000000011011b931 UIKit`-[UIViewController loadViewIfRequired] + 1344
    frame #9: 0x000000011011bc7d UIKit`-[UIViewController view] + 27
    frame #10: 0x000000010fff90c0 UIKit`-[UIWindow addRootViewControllerViewIfPossible] + 61
    frame #11: 0x000000010fff97bd UIKit`-[UIWindow _setHidden:forced:] + 302
    frame #12: 0x000000011000b020 UIKit`-[UIWindow makeKeyAndVisible] + 43
    frame #13: 0x000000010ff8893c UIKit`-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    frame #14: 0x000000010ff8ee15 UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1755
    frame #15: 0x000000010ff8bff0 UIKit`-[UIApplication workspaceDidEndTransaction:] + 188
    frame #16: 0x0000000116da77ac FrontBoardServices`-[FBSSerialQueue _performNext] + 192
    frame #17: 0x0000000116da7b1a FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 45
    frame #18: 0x000000010f61f0a1 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #19: 0x000000010f614fcc CoreFoundation`__CFRunLoopDoSources0 + 556
    frame #20: 0x000000010f614483 CoreFoundation`__CFRunLoopRun + 867
    frame #21: 0x000000010f613e98 CoreFoundation`CFRunLoopRunSpecific + 488
    frame #22: 0x000000010ff8b98d UIKit`-[UIApplication _run] + 402
    frame #23: 0x000000010ff90676 UIKit`UIApplicationMain + 171
    frame #24: 0x000000010ef697dd Findme`main + 109 at AppDelegate.swift:12
    frame #25: 0x0000000111f2992d libdyld.dylib`start + 1

@groue
Copy link
Owner

groue commented Oct 2, 2015

Thanks! It doesn't tell much :-)

OK I'm not sure, but the /db.sqlite path looks suspicious: one is not supposed to write in / on iOS. What about trying a more classical path, inside the documents folder?

@JerrySievert
Copy link
Author

i had previously tried without the / - you got the stack trace from my "let's give it one more attempt but change the path" stack trace.

@groue
Copy link
Owner

groue commented Oct 2, 2015

Will you try with the following code, please?

let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString
let databasePath = documentsPath.stringByAppendingPathComponent("db.sqlite")
dbQueue = try DatabaseQueue(path:  databasePath)

@JerrySievert
Copy link
Author

i just did that, right as you were posting, and managed to get it to work.

thanks!

@JerrySievert
Copy link
Author

        do {
            let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
            dbQueue = try DatabaseQueue(path: documentsPath + "/db.sqlite")
        } catch {
            print("Error opening SQLite Database")
        }

@groue
Copy link
Owner

groue commented Oct 2, 2015

Happy we solved it! Happy GRDB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants