我已经实现了并发nsoperation并启用了ARC。现在我的客户正在经历一场无法重现的崩溃。他给我发了以下崩溃日志:
Date/Time: 2013-04-24 12:23:34.925 -0400
OS Version: Mac OS X 10.8.3 (12D78)
Report Version: 10
Interval Since Last Report: 30946 sec
Crashes Since Last Report: 1
Per-App Interval Since Last Report: 33196 sec
Per-App Crashes Since Last Report: 1
Anonymous UUID: FB8460EE-5199-C6FB-55DC-F927D7F81A80
Crashed Thread: 15 Dispatch queue: com.apple.root.default-priority
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT
Application Specific Information:
objc_msgSend() selector name: isCancelled
Thread 15 Crashed:: Dispatch queue: com.apple.root.default-priority
0 libobjc.A.dylib 0x00007fff877f1250 objc_msgSend + 16
1 Myapp 0x000000010a608807 0x10a601000 + 30727
2 Myapp 0x000000010a650575 0x10a601000 + 324981
3 com.apple.Foundation 0x00007fff8b66212f -[NSBlockOperation main] + 124
4 com.apple.Foundation 0x00007fff8b638036 -[__NSOperationInternal start] + 684
5 com.apple.Foundation 0x00007fff8b63f861 __block_global_6 + 129
6 libdispatch.dylib 0x00007fff832d0f01 _dispatch_call_block_and_release + 15
7 libdispatch.dylib 0x00007fff832cd0b6 _dispatch_client_callout + 8
8 libdispatch.dylib 0x00007fff832ce1fa _dispatch_worker_thread2 + 304
9 libsystem_c.dylib 0x00007fff87d19d0b _pthread_wqthread + 404
10 libsystem_c.dylib 0x00007fff87d041d1 start_wqthread + 13
我的代码如下所示:
-(void)start
{
// Always check for cancellation before launching the task.
if ([self isCancelled])
{
// Must move the operation to the finished state if it is canceled.
[self onCancelSyncOperation];
return;
}
// If the operation is not canceled, begin executing the task.
[self willChangeValueForKey:@"isExecuting"];
[NSThread detachNewThreadSelector:@selector(main) toTarget:self withObject:nil];
executing = YES;
[self didChangeValueForKey:@"isExecuting"];
}
- (void)onCancelSyncOperation
{
[self willChangeValueForKey:@"isFinished"];
[self willChangeValueForKey:@"isExecuting"];
executing = NO;
finished = YES;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];
}
好像已经发布了这个问题?当它试图检查isCancelled?
这可能吗?
答案 0 :(得分:0)
我认为任何人都无法通过查看此日志来告诉您应用崩溃的原因。我没有查看你的代码,但你切断了崩溃日志,所以它只显示系统模块(lib.dispatch ...,com.apple ...)。通常,错误发生在第一次出现的“com.myname ...”中。
如果此类崩溃EXC_BAD_ACCESS (SIGSEGV)
与objc_msgSend()
一起出现,则可能表示您正在尝试向对象发送消息(或者换句话说:调用a一个对象的方法,不再存在了。如果你调用那个对象,很可能你会发现它,如果你把它称为延迟或者在另一个线程或块上,它会更复杂。
找到原因的最佳机会是使用仪器检查您的应用程序,使用启用了NSZombies的分配或泄漏工具(这是默认设置)。您可以从Xcode中启动Instruments。然后尝试重现你的崩溃。如果成功,您可能能够找到发生崩溃的类和位置。
如果您不知道如何处理此答案,请查看Apple的WWDC开发者视频,其中一些显示了如何使用Instruments配置您的应用程序(您需要一个[免费]开发帐户访问视频)。
祝你好运!