yapstudios / YapDatabase

YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers.
Other
3.35k stars 365 forks source link

_NSKeyedUnarchiverHelper dealloc crash #518

Open wongzigii opened 4 years ago

wongzigii commented 4 years ago

Hello there, do you have any ideas for this unusual crash, which is located at this line? BTW, I am using YapDatabase 3.1.

I am trying to read data from database like this:

-(NSArray *)getStationsWithType:(TSLStationType)type
{
    NSMutableArray* datas = [NSMutableArray array];

    [[self.database newConnection] readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {

        NSString *collection = [self typeStringWithType:type];
        [transaction enumerateKeysAndObjectsInCollection:collection usingBlock:^(NSString * _Nonnull key, id  _Nonnull object, BOOL * _Nonnull stop) {

            if ([object isKindOfClass:[TSLStationModel class]]) {
                TSLStationModel *m = object;
                [datas addObject:object];
            }

        }];
    }];

    return datas;
}
??? 0x000000016d782648 0x00000001ee577870
1 CoreFoundation 0x00000001b0b21c98 -[__NSArrayM dealloc]
2 Foundation 0x00000001b0f0cc84 -[_NSKeyedUnarchiverHelper dealloc]
3 Foundation 0x00000001b0f0cbf0 -[NSKeyedUnarchiver dealloc]
4 Foundation 0x00000001b0f5fbc0 +[NSKeyedUnarchiver unarchiveObjectWithData:]
5 YapDatabase 0x00000001054cc208 YapCollectionKeyHash
6 YapDatabase 0x000000010556f010 NSStringFromYapDatabaseSecondaryIndexType
7 YapDatabase 0x000000010556a8b8 NSStringFromYapDatabaseSecondaryIndexType
8 YapDatabase 0x000000010556a764 NSStringFromYapDatabaseSecondaryIndexType
9 MYAPP 0x0000000102a85f7c __42-[TSLStationsStorage getStationsWithType:]_block_invoke (TSLStationsStorage.m:0)
10 YapDatabase 0x0000000105512bb8 YapCollectionKeyHash
11 libdispatch.dylib 0x00000001b0917184 __dispatch_client_callout
12 libdispatch.dylib 0x00000001b08fb198 __dispatch_sync_invoke_and_complete_recurse
13 libdispatch.dylib 0x00000001b08fac90 __dispatch_sync_f_slow
14 YapDatabase 0x0000000105512b30 YapCollectionKeyHash
15 MYAPP 0x0000000102a85e8c -[TSLStationsStorage getStationsWithType:] (TSLStationsStorage.m:232)
16 MYAPP 0x0000000102a4a058 __45-[TSLMapManager getPointsWithType:completed:]_block_invoke (TSLMapManager.m:0)
17 libdispatch.dylib 0x00000001b0916610 __dispatch_call_block_and_release
18 libdispatch.dylib 0x00000001b0917184 __dispatch_client_callout
19 libdispatch.dylib 0x00000001b08fa34c __dispatch_main_queue_callback_4CF$VARIANT$armv81
20 CoreFoundation 0x00000001b0bc85e4 _CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
21 CoreFoundation 0x00000001b0bc35d8 ___CFRunLoopRun
22 CoreFoundation 0x00000001b0bc2adc CFRunLoopRunSpecific
23 GraphicsServices 0x00000001bab63328 GSEventRunModal
24 UIKitCore 0x00000001b4cd063c UIApplicationMain
25 MYAPP 0x00000001029f4770 main (main.m:13)
26 libdyld.dylib 0x00000001b0a4c360 _start

Edit: I've uploaded the xccrashpoint here.

wongzigii commented 4 years ago

https://stackoverflow.com/questions/7557800/nskeyedunarchiver-how-to-prevent-a-crash

I think unarchiveObjectWithData should be wrapped by a try-catch control flow, and unarchiveObjectWithData is deprecated in iOS 12, we need to switch to latest API.