2012-11-27 98 views
1

我在我的項目中使用了HUD。這種情況會發生在我的應用程序中:在主線程中它會做一個動畫,而在子線程中它會調用sleep。 我會收到崩潰日誌是這樣的:可以睡覺(1)調用線程導致崩潰?

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0xd0000008 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 libobjc.A.dylib     0x383d55b0 objc_msgSend + 16 
1 UIKit       0x36b7b822 -[UIAnimator stopAnimation:] + 262 
2 UIKit       0x36c16252 -[UIAnimator(Static) _advanceAnimationsOfType:withTimestamp:] + 290 
3 UIKit       0x36b7b384 -[UIAnimator(Static) _LCDHeartbeatCallback:] + 48 
4 QuartzCore      0x35c7006c CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) + 156 
5 QuartzCore      0x35c6ffc4 CA::Display::IOMFBDisplayLink::callback(__IOMobileFramebuffer*, unsigned long long, unsigned long long, unsigned long long, void*) + 60 
6 IOMobileFramebuffer    0x312a6fd4 IOMobileFramebufferVsyncNotifyFunc + 152 
7 IOKit       0x312ab446 IODispatchCalloutFromCFMessage + 190 
8 CoreFoundation     0x3646d5d8 __CFMachPortPerform + 116 
9 CoreFoundation     0x36478170 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32 
10 CoreFoundation     0x36478112 __CFRunLoopDoSource1 + 134 
11 CoreFoundation     0x36476f94 __CFRunLoopRun + 1380 
12 CoreFoundation     0x363e9eb8 CFRunLoopRunSpecific + 352 
13 CoreFoundation     0x363e9d44 CFRunLoopRunInMode + 100 
14 GraphicsServices    0x385962e6 GSEventRunModal + 70 
15 UIKit       0x36a622fc UIApplicationMain + 1116 
16 YH_EMenu      0x000e36c4 main (main.m:14) 
17 YH_EMenu      0x000dd6cc start + 36 

Thread 1: 
0 libsystem_kernel.dylib   0x38503d98 __workq_kernreturn + 8 
1 libsystem_c.dylib    0x33a27cf6 _pthread_workq_return + 14 
2 libsystem_c.dylib    0x33a27a12 _pthread_wqthread + 362 
3 libsystem_c.dylib    0x33a278a0 start_wqthread + 4 

Thread 2 name: Dispatch queue: com.apple.libdispatch-manager 
Thread 2: 
0 libsystem_kernel.dylib   0x384f3648 kevent64 + 24 
1 libdispatch.dylib    0x33cc8974 _dispatch_mgr_invoke + 792 
2 libdispatch.dylib    0x33cc8654 _dispatch_mgr_thread$VARIANT$mp + 32 

Thread 3 name: WebThread 
Thread 3: 
0 libsystem_kernel.dylib   0x384f2eb4 mach_msg_trap + 20 
1 libsystem_kernel.dylib   0x384f3048 mach_msg + 36 
2 CoreFoundation     0x36478040 __CFRunLoopServiceMachPort + 124 
3 CoreFoundation     0x36476d9e __CFRunLoopRun + 878 
4 CoreFoundation     0x363e9eb8 CFRunLoopRunSpecific + 352 
5 CoreFoundation     0x363e9d44 CFRunLoopRunInMode + 100 
6 WebCore       0x385f9a70 RunWebThread(void*) + 440 
7 libsystem_c.dylib    0x33a3230e _pthread_start + 306 
8 libsystem_c.dylib    0x33a321d4 thread_start + 4 

Thread 4: 
0 libsystem_kernel.dylib   0x38503d98 __workq_kernreturn + 8 
1 libsystem_c.dylib    0x33a27cf6 _pthread_workq_return + 14 
2 libsystem_c.dylib    0x33a27a12 _pthread_wqthread + 362 
3 libsystem_c.dylib    0x33a278a0 start_wqthread + 4 

Thread 5: 
0 libsystem_kernel.dylib   0x38503d98 __workq_kernreturn + 8 
1 libsystem_c.dylib    0x33a27cf6 _pthread_workq_return + 14 
2 libsystem_c.dylib    0x33a27a12 _pthread_wqthread + 362 
3 libsystem_c.dylib    0x33a278a0 start_wqthread + 4 

Thread 6: 
0 libsystem_kernel.dylib   0x385036a4 __semwait_signal + 24 
1 libsystem_c.dylib    0x33a373ce nanosleep + 138 
2 libsystem_c.dylib    0x33a97de6 sleep + 42 
3 YH_EMenu      0x000eb580 -[MainViewController threadENDSHOWHUD:] (MainViewController.m:939) 
4 Foundation      0x342ae678 __NSThread__main__ + 968 
5 libsystem_c.dylib    0x33a3230e _pthread_start + 306 
6 libsystem_c.dylib    0x33a321d4 thread_start + 4 

我也沒辦法解決這個問題。

+2

EXC_BAD_ACCESS錯誤通常表示存在內存問題 - 嘗試利用已釋放的內存,例如。線程睡眠不太可能導致這種情況,並且日誌指出主線程導致崩潰 - 看起來與動畫何時停止有關。你能發佈處理它的代碼嗎? – Xono

+1

我發現了這個Bug。我在子線程中更改UI。 – Andy

回答

-1

請嘗試使用睡眠(1000)1秒。這裏'1000'代表1000ms。

+2

爲什麼你認爲睡眠一毫秒會導致應用程序崩潰? –

+0

你的意思是這個原因導致崩潰? – Andy

+0

睡眠單位是第二位。 – Andy