我有以下代码停止if (time != currentTime)
并启动调试器。我找不到任何有关它的信息,并且尝试记录异常不起作用。
- (void)viewWillAppear:(BOOL)animated {
[self startIt];
}
- (void)viewWillDisappear:(BOOL)animated {
[self stopIt];
}
- (void)startIt {
isRunning = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
@try {
NSTimeInterval time = currentTime;
while (isRunning) {
if (time != currentTime) { // app stops here with EXC_??? (11)
time = currentTime;
// do other work
}
}
}
@catch (NSException *e) {
NSLog(@"Exception %@", e);
}
});
}
// Delegate method called when broadcasting time
- (void)updateCurrentTime:(NSInteger)time {
@synchronized(self) {
currentTime = time;
}
[anotherView doStuffWIthTime:time];
}
- (void)stopIt {
isRunning = NO;
}
查看堆栈跟踪对我没有多大帮助:
* thread #6: tid = 0x2503, 0x0021e6e3 Project`__46-[MyViewControlleriPad startRunQueue]_block_invoke() + 131 at MyViewControlleriPad.m:343, stop reason = EXC_??? (11) (code=0, subcode=0x0)
frame #0: 0x0021e6e3 Project`__46-[MyViewControlleriPad startRunQueue]_block_invoke() + 131 at MyViewControlleriPad.m:343
frame #1: 0x03f1653f libdispatch.dylib`_dispatch_call_block_and_release + 15
frame #2: 0x03f28014 libdispatch.dylib`_dispatch_client_callout + 14
frame #3: 0x03f192e8 libdispatch.dylib`_dispatch_root_queue_drain + 335
frame #4: 0x03f19450 libdispatch.dylib`_dispatch_worker_thread2 + 39
frame #5: 0x96f33e72 libsystem_c.dylib`_pthread_wqthread + 441
编辑:更新以显示isRunning
正在设置。我现在意识到我没有同步访问它。这会解决这个问题吗?我在想它是与currentTime
。