【问题标题】:SIGSEGV : Sporadic crash issueSIGSEGV:零星的崩溃问题
【发布时间】:2017-06-13 14:19:34
【问题描述】:

这是我第一次尝试解决 iOS 应用程序中的崩溃问题。在这里分享一些崩溃日志。

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x97ad6beb8
Crashed Thread:  11

Application Specific Information:
objc_msgSend() selector name: length

这是我的第 11 个线程。

Thread 11 Crashed:
0   libobjc.A.dylib                      0x0000000180558150 objc_msgSend + 16
1   Foundation                           0x00000001824f3f60 -[NSString compare:] + 28
2   Foundation                           0x00000001824d88e0 _NSCompareObject + 60
3   CoreFoundation                       0x0000000181a99bd0 __CFSimpleMergeSort + 88
4   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
5   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
6   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
7   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
8   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
9   CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
10  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
11  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
12  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
13  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
14  CoreFoundation                       0x0000000181a99c60 __CFSimpleMergeSort + 232
15  CoreFoundation                       0x00000001819c585c CFSortIndexes + 460
16  CoreFoundation                       0x00000001819c6f9c CFMergeSortArray + 372
17  Foundation                           0x00000001824d80e8 _sortedObjectsUsingDescriptors + 568
18  Foundation                           0x00000001825c64e0 -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 536
19  Eikon                                0x0000000100198b98 __51-[EIKNewsHeadlineStoreManager saveHeadlines:block:]_block_invoke (EIKNewsHeadlineStoreManager.m:67)
20  CoreData                             0x0000000183e5e214 developerSubmittedBlockToNSManagedObjectContextPerform + 148
21  libdispatch.dylib                    0x000000018099a9a0 _dispatch_client_callout + 12
22  libdispatch.dylib                    0x00000001809a8ad4 _dispatch_queue_serial_drain + 924
23  libdispatch.dylib                    0x000000018099e2cc _dispatch_queue_invoke + 880
24  libdispatch.dylib                    0x00000001809a8fa8 _dispatch_queue_override_invoke + 340
25  libdispatch.dylib                    0x00000001809aaa50 _dispatch_root_queue_drain + 536
26  libdispatch.dylib                    0x00000001809aa7d0 _dispatch_worker_thread3 + 120
27  libsystem_pthread.dylib              0x0000000180ba31d0 _pthread_wqthread + 1092
28  libsystem_pthread.dylib              0x0000000180ba2d7c start_wqthread + 0

我要做的是每 5 或 10 秒从服务器获取一些新闻标题,使用 NSSortDescriptors 按某种顺序对它们进行排序,然后将它们存储在我的 CoreData 中。这正是 saveHeadlines:block 方法在我的课堂上所做的。

objc_msgSend() selector name: length 到底是什么意思?任何帮助表示赞赏。

注意:这是一个零星的问题。当我在模拟器或我的设备中测试时,它不会崩溃。但是我们应用的一些用户报告了这次崩溃。

已编辑问题:在 saveHeadlines:block 方法中

        __weak typeof(self) weakSelf = self;
    [self.privateMOC performBlock:^{

        NSMutableArray *newsTopics = [[EIKNewsTopicStoreManager managedObjectsInManagedObjectContext:self.privateMOC] mutableCopy];
        [newsTopics addObjectsFromArray:[EIKNewsTopicStoreManager topicsManagedObjectForNewsFeedInContext:self.privateMOC]];
        weakSelf.storedHeadlines = [NSMutableSet set];

        for (NSManagedObject *storedTopic in newsTopics) {
            [weakSelf.storedHeadlines addObjectsFromArray:[[storedTopic valueForKey:EIKFeedTopicRelationshipItems] allObjects]];
        }

        NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:EIKNewsHeadlineAttributeHeadlineId ascending:YES]];
        NSArray *orderedItems = [items sortedArrayUsingDescriptors:sortDescriptors];
        NSArray *orderedHeadlines = [weakSelf.storedHeadlines sortedArrayUsingDescriptors:sortDescriptors];

崩溃发生在最后一行。即

 NSArray *orderedHeadlines = [weakSelf.storedHeadlines sortedArrayUsingDescriptors:sortDescriptors];

不知道为什么。!

我的 NSManagedObjectContext 是这样初始化的[即上面代码所示的 privateMOC]

NSManagedObjectContext *confinementContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];

【问题讨论】:

    标签: ios objective-c core-data xcode8 crash-reports


    【解决方案1】:

    这里没有太多信息,但在我看来NSManagedObjectContext 在您正在执行操作的线程上无效。 请确保您在上下文的私有队列上执行所有操作。例如,您可以使用performBlock:performBlockAndWait: 来执行此操作。 此外,您不能在与获取它们的线程不同的线程上重用 NSManagedObject 的实例。 希望对您有所帮助。

    【讨论】:

    • 嗨,在上面提到的方法中,我使用“performBlock:”来保存我获取到 CoreData 的所有标题。
    • 你能展示获取它们的代码吗?您确定 fetch 也在 performBlock 中吗?
    • 请查看已编辑的问题。另请参阅崩溃的行。
    • @kkodev。 SIGSEGV 表示我们正在尝试访问无效的内存位置,对吗?
    • 请看我对 NSManagedObjectContext 的初始化。正如你所说,我为此使用了一个私人队列。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 2015-03-28
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多