i’m getting an _WebThreadLockFromAnyThread error in my app. it doesn’t crash my app (every other error like this has crashed my app).
i’m having trouble tracking down where the offending line of code is.
i know this error is when i try to update the UI on a secondary thread. i am only using 1 thread other then main for KVO’ing. i make all my method calls with
[self foo]
the error is:
void _WebThreadLockFromAnyThread(bool), 0xb29ca60: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
the error appears in my log at the same spot every execution, it prints between these two log entries:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"observeValueForKeyPath thread%@", [NSThread currentThread]);
if ([keyPath isEqualToString:MAXY])
{
NSLog(@"current tabDictionary:%@", self.tabDictionary);
but there should be nothing to do with changing the UI with my if stmt so i’m assuming its happening somewhere else in my program.
can i use its memory address to figure out which object it is? or which thread it is trying from?
I’m guessing that
tabDictionarycontains instances of UIViewController, and that your call to NSLog is causing properties of the view controller to be accessed in order to generate the string being logged. That’s your UIKit access on a secondary thread.When
observeValueForKeyPath:is called you have no guarantees regarding what thread you are on. If it’s important, you should check whether or not you are on the main thread and, if not, useperformSelector:onMainThread:ordispatch_asyncto make sure that you are.