WebTryThreadLock SEGV

时间:2011-05-06 16:54:00

标签: ios

我在_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

Thread 1 Crashed:
0   WebCore                             0x34c263c8 _WebTryThreadLock(bool) + 112
1   WebCore                             0x34c281b1 WebThreadLock + 53
2   UIKit                               0x35a3765f -[UITextView dealloc] + 31
3   CoreFoundation                      0x30329c43 -[NSObject(NSObject) release] + 31
4   UIKit                               0x358ad5f5 -[UIView(Hierarchy) removeFromSuperview] + 365
5   UIKit                               0x359426cd -[UIScrollView removeFromSuperview] + 49
6   UIKit                               0x35a352f1 -[UITextView removeFromSuperview] + 73
7   UIKit                               0x358c0de3 -[UIView dealloc] + 155
8   CoreFoundation                      0x30329c43 -[NSObject(NSObject) release] + 31
9   UIKit                               0x3591900f -[UIViewController dealloc] + 175
10  Foo                                 0x0000c167 -[FooViewController dealloc] (FooViewController.m:646)
11  CoreFoundation                      0x30329c43 -[NSObject(NSObject) release] + 31
12  CoreFoundation                      0x3032a1a1 CFRelease + 69
13  CoreFoundation                      0x3032cebb _CFAutoreleasePoolPop + 147
14  libdispatch.dylib                   0x33d0b6a5 _dispatch_worker_thread2 + 373
15  libsystem_c.dylib                   0x33e0a591 _pthread_wqthread + 265

我无法在自己的测试中重现这一点,所以我不确定触发它的原因。它肯定不会经常发生。我在WebThreadLock中看到了在尝试从主线程之外的线程修改UIKit元素时出现崩溃的问题。

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

1 个答案:

答案 0 :(得分:2)

我想通过Rentzsch的发布/保留调试技巧来解决这个问题:

http://rentzsch.tumblr.com/post/3895140826/retain-release-debugging

问题是我从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]并检查我的控制器是否是最后一个对象,并且从未崩溃。