couchbase / couchbase-lite-ios

Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps.
Apache License 2.0
1.62k stars 297 forks source link

Crash instantiating a CBLModel from a to-many relation #62

Closed snej closed 11 years ago

snej commented 11 years ago

@nl reported a crash accessing a CBLModel to-many relation:

2013-06-25 17:24:32.781 StoryPlayer[8026:907] +[NSArray modelForDocument:]: unrecognized selector sent to class 0x24b4bb4
(lldb) bt
* thread #1: tid = 0x1a03, 0x9a12b922 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGABRT
    frame #0: 0x9a12b922 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x98ed01bc libsystem_pthread.dylib`pthread_kill + 101
    frame #2: 0x01e3457b libsystem_sim_c.dylib`abort + 140
    frame #3: 0x01fb4f7b libc++abi.dylib`abort_message + 105
    frame #4: 0x01fb2a25 libc++abi.dylib`default_terminate() + 34
    frame #5: 0x01c410c1 libobjc.A.dylib`_objc_terminate() + 94
    frame #6: 0x01fb2a65 libc++abi.dylib`safe_handler_caller(void (*)()) + 13
    frame #7: 0x01fb2acd libc++abi.dylib`std::terminate() + 23
    frame #8: 0x01fb3bc2 libc++abi.dylib`__cxa_throw + 110
    frame #9: 0x01c40f89 libobjc.A.dylib`objc_exception_throw + 311
    frame #10: 0x0241a2ad CoreFoundation`+[NSObject(NSObject) doesNotRecognizeSelector:] + 253
    frame #11: 0x0237ebbc CoreFoundation`___forwarding___ + 588
    frame #12: 0x0237e94e CoreFoundation`_CF_forwarding_prep_0 + 14
    frame #13: 0x000d17ef StoryPlayer`-[CBLModel modelWithDocID:forProperty:](, _cmd=0x00106f4c, docID=0x09075f30, property=0x09077830) + 331 at CBLModel.m:422
    frame #14: 0x000d6819 StoryPlayer`-[CBLModelArray objectAtIndex:](self=0x09076600, _cmd=0x0247e196, index=0) + 165 at CBLModelArray.m:66
    frame #15: 0x02380868 CoreFoundation`-[NSArray getObjects:range:] + 264
    frame #16: 0x02380a76 CoreFoundation`-[NSArray countByEnumeratingWithState:objects:count:] + 326
    frame #17: 0x02388dac CoreFoundation`__NSArrayEnumerate + 364
    frame #18: 0x02388a16 CoreFoundation`-[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
    frame #19: 0x02388925 CoreFoundation`-[NSArray enumerateObjectsUsingBlock:] + 53
    frame #20: 0x00034898 StoryPlayer`-[SPStory authorNames](self=0x09057560, _cmd=0x000fa1e2) + 200 at SPStory.m:70
snej commented 11 years ago

The code for instantiating a new CBLModel from a CBLModelArray didn't work at all, and unfortunately the test case didn't hit this case (because it would have needed to re-open the database to do so.)

I've fixed it now.