Ios WebTryThreadLock SEGV

Ios WebTryThreadLock SEGV,ios,Ios,我在WebTryThreadLock中偶尔会看到这样的崩溃报告: Exception Type: SIGSEGV Exception Codes: SEGV_ACCERR at 0xffffffffbbadbeef Thread 5 Crashed: 0 WebCore 0x00005822 _WebTryThreadLock(bool) + 158 1 WebCore

我在WebTryThreadLock中偶尔会看到这样的崩溃报告:

    Exception Type:  SIGSEGV
    Exception Codes: SEGV_ACCERR at 0xffffffffbbadbeef

    Thread 5 Crashed:
0   WebCore                             0x00005822 _WebTryThreadLock(bool) + 158
1   WebCore                             0x0000576f WebThreadLock + 47
2   UIKit                               0x001ae019 -[UIWebView dealloc] + 73
3   CoreFoundation                      0x00006f7b -[NSObject(NSObject) release] + 31
4   Foo                                 0x0000c001 -[FooViewController dealloc] (FooViewController.m:653)
5   CoreFoundation                      0x00006f7b -[NSObject(NSObject) release] + 31
6   CoreFoundation                      0x0000b3c9 CFRelease + 69
7   CoreFoundation                      0x0000a8df _CFAutoreleasePoolPop + 147
8   libSystem.B.dylib                   0x000d6c04 _dispatch_worker_thread2 + 228
9   libSystem.B.dylib                   0x0007b251 _pthread_wqthread + 265

但我无法在自己的测试中重现这一点,所以我不确定是什么触发了它。这肯定不经常发生。我在WebThreadLock中看到过当试图从主线程以外的线程修改UIKit元素时出现崩溃的情况


我想这一定是这里发生的事情,因为_dispatch_worker_thread2告诉我这是一个GCD线程,而不是UIApplicationMain线程。我必须在一个GCD线程上运行一些东西,在主线程释放FooViewController之后,该线程保持FooViewController的运行状态,我猜在这个非主线程中发生的removeFromSuperview调用是触发问题的原因。

多亏了Rentzsch的发布/保留调试技巧,我才发现了这一点:

问题是我从GCD线程调用了[UINavigationController visibleViewController],这导致该线程在我的FooViewController上调用retain:

0   Foo                                 0x00009d98 -[FooViewController retain] + 216
1   UIKit                               0x0049e5ad -[UINavigationController topViewController] + 61
2   UIKit                               0x0049e4ca -[UINavigationController visibleViewController] + 133
3   Foo                                 0x0003c0bd -[BarViewController updateStatus:animated:] + 147
4   Foo                                 0x0003799e -[BarViewController reallyProcessMetadata] + 229
5   Foo                                 0x0003650e __39-[BarViewController processMetadata]_block_invoke_0828 + 408
6   libdispatch_sim.dylib               0x01a63289 _dispatch_call_block_and_release + 16
7   libdispatch_sim.dylib               0x01a6658a _dispatch_worker_thread2 + 252
8   libSystem.B.dylib                   0x98d2bd21 _pthread_wqthread + 390
9   libSystem.B.dylib                   0x98d2bb66 start_wqthread + 30
当该线程的自动释放池耗尽时,它是最后一个举起FooViewController的人,它会导致崩溃。如果您足够幸运,能够在调试器中重现该线程,您将在控制台中看到:

2011-05-06 19:34:40.651 Foo[59365:943b] bool _WebTryThreadLock(bool), 0x11393b30: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
Program received signal:  “EXC_BAD_ACCESS”.
因此,在我的例子中,解决方案是不从此线程使用visibleViewController。我之前只是调用[UINavigationController viewControllers]并检查我的控制器是否是最后一个对象,但从未崩溃

2011-05-06 19:34:40.651 Foo[59365:943b] bool _WebTryThreadLock(bool), 0x11393b30: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
Program received signal:  “EXC_BAD_ACCESS”.