views:

38

answers:

1

I'm getting the following error:

2010-05-11 17:46:28.475 MyApp[54112:5e1b] bool _WebTryThreadLock(bool), 0x140faa0: 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...

Is there any way for me to figure out where [54112:5e1b] is in my code, so I can try to narrow down the error?

Thanks.

A: 

You may be able to narrow down the error simply by making sure you don't do anything to UIKit objects in a secondary thread, it's what the error message seems to be accusing you of. Background threads are for background tasks - you can do anything you like but when your background thread needs to have an effect on your view (as in model, view, controller) you need to do something to communicate with your main thread and cause it to do the change - like performSelectorOnMainThread.

But Mac OS X Debugging Magic is a very popular and useful document that could help find exactly what is at that address.

Adam Eberbach
I'll take a look. A related question about not "doing anything to UIKit objects" in a secondary thread. Is a call like "[UIApplication sharedApplication].networkActivityIndicatorAvailable = YES" allowed? Just wondering how restrictive this is. Thanks.
Greg Maletic
It's really restrictive - you can't assume anything in UIKit will work if you do it from a secondary thread. You need to add a method that sets networkActivityIndicatorAvailable but is invoked on the main thread using performSelectorOnMainThread.
Adam Eberbach
That's pretty tricky, isn't it? I mean, I happen to know that "[UIApplication sharedApplication].networkActivityIndicatorAvailable" draws to the screen. But nothing about its name would indicate that it does. It doesn't seem like there's any way to be 100% compliant with this restriction unless you don't make -any- Cocoa calls without doing so in the main thread. Which would be absurd.
Greg Maletic
It's all there in developer docs - if your object (UIApplication) says it is part of UIKit.Framework, the restriction applies. One example of an object you can use in a secondary thread is NSTimer.
Adam Eberbach