title: iOS - Determining the cause of a crash (from a crash report) in _WebTryThreadLock
body: <p>I have been trying to figure out what is causing one of the top crashes in my iOS application. It looks like there is some layout happening on a background thread which is causing it to crash. Is there any way to determine what I might be doing that is triggering this relayout? I assume from the stack that it is related to a UIWebView when my app is being brought back into the foreground. </p>
  
  <p>Other stackoverflow threads on the topic seem to mention things like triggering a table reload on a background thread. As far as I can see all the webView delegate methods get called on the main thread. Is there some case where this is not true or are there some other methods which get called on a background thread and I'm just not aware?</p>
  
  <p>Web Thread - Crashed.</p>
  
  <pre><code>0    WebCore _WebTryThreadLock(bool) + 297
  1    WebCore _WebTryThreadLock(bool) + 288
  2    WebCore WebThreadLock + 66
  3    UIKit -[UIWebDocumentView(UIWebDocumentViewTextSelecting) selectionBaseWritingDirection] + 10
  4    UIKit -[UITextField _currentTextAlignment] + 86
  5    UIKit -[UITextField _showsClearButtonWhenNonEmpty:] + 58
  6    UIKit -[UITextField _textRectForBounds:forEditing:] + 678
  7    UIKit -[UITextField editingRectForBounds:] + 52
  8    UIKit -[UITextField editRect] + 70
  9    UIKit -[UITextField layoutSubviews] + 1320
  10   UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 258
  11   QuartzCore -[CALayer layoutSublayers] + 214
  12   QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) + 460
  13   QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
  14   QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 238
  15   QuartzCore CA::Transaction::commit() + 316
  16   QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 60
  17   CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
  18   CoreFoundation __CFRunLoopDoObservers + 276
  19   CoreFoundation CFRunLoopRunSpecific + 394
  20   CoreFoundation CFRunLoopRunInMode + 104
  21   WebCore RunWebThread(void*) + 444
  22   libsystem_c.dylib pthread_start + 308
  </code></pre>
  
  <p>Main - Thread</p>
  
  <pre><code>0    libsystem_kernel.dylib __psynch_mutexwait + 24
  1    libsystem_c.dylib pthread_mutex_lock + 392
  2    WebCore _WebTryThreadLock(bool) + 336
  3    WebCore WebThreadLock + 66
  4    WebKit -[WebDatabasePauser applicationWillEnterForeground] + 16
  5    CoreFoundation _CFXNotificationPost + 1426
  6    Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
  7    UIKit -[UIApplication _sendWillEnterForegroundCallbacks] + 154
  8    UIKit -[UIApplication _handleApplicationResumeEvent:] + 1094
  9    UIKit -[UIApplication handleEvent:withNewEvent:] + 1292
  10   UIKit -[UIApplication sendEvent:] + 72
  11   UIKit _UIApplicationHandleEvent + 6154
  12   GraphicsServices _PurpleEventCallback + 590
  13   CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
  14   CoreFoundation __CFRunLoopDoSources0 + 212
  15   CoreFoundation __CFRunLoopRun + 646
  16   CoreFoundation CFRunLoopRunSpecific + 356
  17   CoreFoundation CFRunLoopRunInMode + 104
  18   GraphicsServices GSEventRunModal + 74
  19   UIKit UIApplicationMain + 1120
  20   AppName main.m line 23
  </code></pre>