iOS WKWebView JavaScriptCore WTFCrash - ios

I added an webview instance on our app. But, sometimes crash occurs.
The crash called JavaScriptCore WTFCrash on call stack.
Crashed: com.apple.main-thread
0 JavaScriptCore 0x26062a22 WTFCrash + 53
1 JavaScriptCore 0x260629cd WTFPrintBacktrace + 128
2 WebKit 0x29a2ab95 WTF::HashTable<unsigned long long, WTF::KeyValuePair<unsigned long long, WTF::RefPtr<WebKit::CallbackBase> >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned long long, WTF::RefPtr<WebKit::CallbackBase> > >, WTF::IntHash<unsigned long long>, WTF::HashMap<unsigned long long, WTF::RefPtr<WebKit::CallbackBase>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<WTF::RefPtr<WebKit::CallbackBase> > >::KeyValuePairTraits, WTF::HashTraits<unsigned long long> >::begin() const + 30
3 WebKit 0x29a2ab4d WTF::Vector<WTF::RefPtr<WebKit::CallbackBase>, 0ul, WTF::CrashOnOverflow, 16ul>::reserveCapacity(unsigned long) + 24
4 WebKit 0x29a2aaa5 WTF::Vector<WTF::RefPtr<WebKit::CallbackBase>, 0ul, WTF::CrashOnOverflow, 16ul>::resize(unsigned long) + 44
5 WebKit 0x29a2a955 void WebKit::invalidateCallbackMap<WTF::RefPtr<WebKit::CallbackBase> >(WTF::HashMap<unsigned long long, WTF::RefPtr<WebKit::CallbackBase>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<WTF::RefPtr<WebKit::CallbackBase> > >&, WebKit::CallbackBase::Error) + 104
6 WebKit 0x29ad18b1 WebKit::WebPageProxy::resetState(WebKit::WebPageProxy::ResetStateReason) + 456
7 WebKit 0x29ad0897 WebKit::WebPageProxy::close() + 78
8 WebKit 0x29b8496d -[WKWebView dealloc] + 120
9 libobjc.A.dylib 0x223c13a9 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 388
10 CoreFoundation 0x22b1af89 _CFAutoreleasePoolPop + 16
11 CoreFoundation 0x22b2a251 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 140
12 UIKit 0x2719f2ed -[UIViewController _setViewAppearState:isAnimating:] + 1088
13 UIKit 0x272152d1 -[UIViewController __viewDidDisappear:] + 172
14 UIKit 0x2719f6d3 -[UIViewController _endAppearanceTransition:] + 258
15 UIKit 0x2725b6fb -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 886
16 UIKit 0x2733680f __49-[UINavigationController _startCustomTransition:]_block_invoke + 210
17 UIKit 0x272b4157 -[_UIViewControllerTransitionContext completeTransition:] + 90
18 UIKit 0x27418c7b __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke95 + 682
19 UIKit 0x271c1ba5 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540
20 UIKit 0x271c1685 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204
21 UIKit 0x271c157f -[UIViewAnimationState animationDidStop:finished:] + 78
22 QuartzCore 0x25221689 CA::Layer::run_animation_callbacks(void*) + 252
23 libdispatch.dylib 0x2277980f _dispatch_client_callout + 22
24 libdispatch.dylib 0x22787ba9 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524
25 CoreFoundation 0x22bcdb6d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
26 CoreFoundation 0x22bcc067 __CFRunLoopRun + 1574
27 CoreFoundation 0x22b1b229 CFRunLoopRunSpecific + 520
28 CoreFoundation 0x22b1b015 CFRunLoopRunInMode + 108
29 GraphicsServices 0x2410bac9 GSEventRunModal + 160
30 UIKit 0x271ef189 UIApplicationMain + 144
31 App 0x12d600 main (AppDelegate.swift:14)
32 libdispatch.dylib 0x227c3873 (Missing)
Does anybody has experienced similar this issue?

Your code has two issues:
- stringByEvaluatingJavaScriptFromString: returns an autoreleased NSString. You thus do not need to use stringWithFormat:.
- Your code does not have a valid format either.
pageText = [NSString stringWithFormat:#"%#", [webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"];
would correct the format error, however, because you are assigning pageText you run the risk of a crash later due to the autorelease.
The following is all that is necessary. NB: I am assuming that the Javascript is valid....
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[pageText release], pageText = nil;
pageText = [[webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"] retain];
if (!pageText)
// innerHTML was empty
pageText = [[webView stringByEvaluatingJavaScriptFromString:#"document.body"] retain];
}
Note that the retain is added because you are assigning the pageText ivar instead of using a setter. Make sure you add [pageText release]; in your dealloc to prevent leaks. Be very careful when trying to access pageText elsewhere in your code as it could still be nil. Be defensive.

Related

FMDatabaseQueue crash

I'm using FMDB in my app. I'm seeing this random crash happening during the app launch.
-(void) addActivities{
[[[DB sharedManager]getSecureQueue] inTransaction:^(FMDatabase * _Nonnull db, BOOL * _Nonnull rollback) {
//process data
}];
}
getSecureQueue returns a FMDatabaseQueue:
_secureQueue= [FMDatabaseQueue databaseQueueWithPath:dbPath];
I checked that _SecureQueue is not nil.
The crash log:
Crashed: fmdb.<FMDatabaseQueue: 0x170242610>
0 libdispatch.dylib 0x18ad83634 _dispatch_barrier_sync_f_slow + 560
1 FMDB 0x101040bd8 -[FMDatabaseQueue beginTransaction:withBlock:] (FMDatabaseQueue.m:228)
2 FMDB 0x101040bd8 -[FMDatabaseQueue beginTransaction:withBlock:] (FMDatabaseQueue.m:228)
3 iPhoneHandheldACT 0x1001e4870 -[HHCTabBarController addActivities] (HHCTabBarController.m:145)
4 iPhoneHandheldACT 0x1001e553c __49-[HHCTabBarController migrateIntoRealm]_block_invoke (HHCTabBarController.m:226)
5 FMDB 0x101040ac4 __30-[FMDatabaseQueue inDatabase:]_block_invoke (FMDatabaseQueue.m:188)
6 libdispatch.dylib 0x18ad729a0 _dispatch_client_callout + 16
7 libdispatch.dylib 0x18ad7fee0 _dispatch_barrier_sync_f_invoke + 84
8 FMDB 0x101040a34 -[FMDatabaseQueue inDatabase:] (FMDatabaseQueue.m:202)
9 iPhoneHandheldACT 0x1001e4ce8 -[HHCTabBarController migrateIntoRealm] (HHCTabBarController.m:181)
10 iPhoneHandheldACT 0x1001e4270 -[HHCTabBarController viewDidLoad] (HHCTabBarController.m:77)
11 UIKit 0x191fecb04 -[UIViewController loadViewIfRequired] + 1036
12 UIKit 0x192004590 -[UIViewController __viewWillAppear:] + 132
13 UIKit 0x192188e18 -[UINavigationController _startCustomTransition:] + 1144
14 UIKit 0x1920a37bc -[UINavigationController _startDeferredTransitionIfNeeded:] + 676
15 UIKit 0x1920a3424 -[UINavigationController __viewWillLayoutSubviews] + 64
16 UIKit 0x1920a3388 -[UILayoutContainerView layoutSubviews] + 188
17 UIKit 0x191fe9cc0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200
18 QuartzCore 0x18f1da274 -[CALayer layoutSublayers] + 148
19 QuartzCore 0x18f1cede8 CA::Layer::layout_if_needed(CA::Transaction*) + 292
20 QuartzCore 0x18f1ceca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
21 QuartzCore 0x18f14a34c CA::Context::commit_transaction(CA::Transaction*) + 252
22 QuartzCore 0x18f1713ac CA::Transaction::commit() + 504
23 QuartzCore 0x18f171e78 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 120
24 CoreFoundation 0x18be689a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
25 CoreFoundation 0x18be66630 __CFRunLoopDoObservers + 372
26 CoreFoundation 0x18bd96dc4 CFRunLoopRunSpecific + 456
27 UIFoundation 0x191f95134 -[NSHTMLReader _loadUsingWebKit] + 1764
28 Foundation 0x18c9af50c __NSThreadPerformPerform + 340
29 CoreFoundation 0x18be6942c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
30 CoreFoundation 0x18be68d9c __CFRunLoopDoSources0 + 540
31 CoreFoundation 0x18be669a8 __CFRunLoopRun + 744
32 CoreFoundation 0x18bd96da4 CFRunLoopRunSpecific + 424
33 GraphicsServices 0x18d801074 GSEventRunModal + 100
34 UIKit 0x192051c9c UIApplicationMain + 208
35 iPhoneHandheldACT 0x1000a7bf4 main (main.m:16)
36 libdyld.dylib 0x18ada559c start + 4
On line 8, it looks like you're already inside an inDatabase call (i.e. you're already in FMDatabaseQueue when you try to enter the queue again). Don't try to enter serial queue when you're already inside that serial queue. At best, you'll deadlock. If you do that at the wrong time (e.g. during app startup), the watchdog process will kill your app with exception code 0x8badf00d ("ate bad food"; lol; see Technical Note TN2151: Understanding and Analyzing Application Crash Reports).

ios: NSAttributedString allocation bug

I have a view which allocates a UILabel and sets the attributed string using NSAttributedString from HTML string. I get the crash during initialising the NSAttributedString. Following is the stack trace of the error:
Thread : Crashed: com.apple.main-thread
0 ??? 0x15e9d6c0
1 QuartzCore 0x2d967993 CA::Display::DisplayLink::get_link(CA::Display::Display*, __CFRunLoop*, X::List<__CFString const*> const*) + 254
2 QuartzCore 0x2d967723 CA::Display::DisplayLinkItem::update_link(__CFRunLoop*) + 162
3 QuartzCore 0x2d98a823 CA::Display::DisplayLinkItem::dispatch() + 170
4 QuartzCore 0x2d98a643 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 366
5 IOMobileFramebuffer 0x3288dc07 IOMobileFramebufferVsyncNotifyFunc + 90
6 IOKit 0x2b827001 IODispatchCalloutFromCFMessage + 256
7 CoreFoundation 0x2a86324d __CFMachPortPerform + 132
8 CoreFoundation 0x2a8737cb __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
9 CoreFoundation 0x2a873767 __CFRunLoopDoSource1 + 346
10 CoreFoundation 0x2a871d69 __CFRunLoopRun + 1608
11 CoreFoundation 0x2a7be201 CFRunLoopRunSpecific + 476
12 CoreFoundation 0x2a7be013 CFRunLoopRunInMode + 106
13 UIFoundation 0x3629bb7f -[NSHTMLReader _loadUsingWebKit] + 1950
14 UIFoundation 0x3629ce31 -[NSHTMLReader attributedString] + 24
15 UIFoundation 0x36244445 _NSReadAttributedStringFromURLOrData + 5648
16 UIFoundation 0x36242dad -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 116
17 PageViewScrollView 0x0002ff54 #!objc ext.UIKit.ObjectiveC.NSAttributedString.init (ObjectiveC.NSAttributedString.Type)(data : ObjectiveC.NSData, options : Swift.Optional<Swift.Dictionary<ObjectiveC.NSObject, Swift.AnyObject>>, documentAttributes : Swift.AutoreleasingUnsafeMutablePointer<Swift.Optional<ObjectiveC.NSDictionary>>, error : Swift.AutoreleasingUnsafeMutablePointer<Swift.Optional<ObjectiveC.NSError>>) -> Swift.Optional<ObjectiveC.NSAttributedString> (HTMLTextView.swift)
18 PageViewScrollView 0x00029da4 ext.UIKit.ObjectiveC.NSAttributedString.init (ObjectiveC.NSAttributedString.Type)(data : ObjectiveC.NSData, options : Swift.Optional<Swift.Dictionary<ObjectiveC.NSObject, Swift.AnyObject>>, documentAttributes : Swift.AutoreleasingUnsafeMutablePointer<Swift.Optional<ObjectiveC.NSDictionary>>, error : Swift.AutoreleasingUnsafeMutablePointer<Swift.Optional<ObjectiveC.NSError>>) -> Swift.Optional<ObjectiveC.NSAttributedString> (HTMLTextView.swift)
19 PageViewScrollView 0x00026fd4 PageViewScrollView.HTMLTextView.init (PageViewScrollView.HTMLTextView.Type)(frame : C.CGRect) -> PageViewScrollView.HTMLTextView (HTMLTextView.swift:33)
20 PageViewScrollView 0x000286ac PageViewScrollView.HTMLTextView.__allocating_init (PageViewScrollView.HTMLTextView.Type)(frame : C.CGRect) -> PageViewScrollView.HTMLTextView (HTMLTextView.swift)
21 PageViewScrollView 0x0003fe4c PageViewScrollView.ViewController.getView (PageViewScrollView.ViewController)(Swift.Int) -> Swift.Optional<ObjectiveC.UIView> (ViewController.swift:149)
22 PageViewScrollView 0x0003c7f8 PageViewScrollView.ViewController.scrollViewDidScroll (PageViewScrollView.ViewController)(ObjectiveC.UIScrollView) -> () (ViewController.swift:86)
23 PageViewScrollView 0x0003f5fc #objc PageViewScrollView.ViewController.scrollViewDidScroll (PageViewScrollView.ViewController)(ObjectiveC.UIScrollView) -> () (ViewController.swift)
24 UIKit 0x2e1dc115 -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 64
25 UIKit 0x2df451d5 -[UIScrollView setContentOffset:] + 632
26 UIKit 0x2e0be771 -[UIScrollView _smoothScrollWithUpdateTime:] + 3120
27 QuartzCore 0x2d98a7db CA::Display::DisplayLinkItem::dispatch() + 98
28 QuartzCore 0x2d98a643 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 366
29 IOMobileFramebuffer 0x3288dc07 IOMobileFramebufferVsyncNotifyFunc + 90
30 IOKit 0x2b827001 IODispatchCalloutFromCFMessage + 256
31 CoreFoundation 0x2a86324d __CFMachPortPerform + 132
32 CoreFoundation 0x2a8737cb __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
33 CoreFoundation 0x2a873767 __CFRunLoopDoSource1 + 346
34 CoreFoundation 0x2a871d69 __CFRunLoopRun + 1608
35 CoreFoundation 0x2a7be201 CFRunLoopRunSpecific + 476
36 CoreFoundation 0x2a7be013 CFRunLoopRunInMode + 106
37 GraphicsServices 0x3228f201 GSEventRunModal + 136
38 UIKit 0x2df8aa09 UIApplicationMain + 1440
39 PageViewScrollView 0x000448f4 main (AppDelegate.swift:14)
40 libdyld.dylib 0x397a3aaf start + 2
Here is the link to the source code of app where I've used this function. Basically it's a view pager using UIScrollView where views are added and removed as the user so as to keep minimal number of total view in memory. During initialisation of new views containing UILabel with NSAttributedString the above occurs. While scrolling from one view to other new view are created and older are removed from scrollView
I actually found the bug. The problem was that scrollViewDidScroll callbacks are sent on background thread. And I was performing UI updates on background which was causing the problem. Executing the code on main thread using dispatch_async(dispatch_get_main_queue(), block solved the issue.

Random crash in possibly UIWebView

The callstack is below. I have been kinda stumped about this. The app crashes randomly with this callstack. The only clue I have is its always when the user is dealing with UIWebViews.
Could it be possibly because that I am not nilling out the webview delegates, or some video elements in the page that is being rendered? Has anyone seen something similar?
Thanks!
The UIWebView is a child of a view in a UIViewController.
The viewDidLoad is where the webView is initialized
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.webView.delegate = self;
self.webView.scalesPageToFit = YES;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.startingUrl]]];
}
Thread : Crashed: WebThread
0 libobjc.A.dylib 0x0000000197487bd0 objc_msgSend + 16
1 UIKit 0x000000018a956ad8 -[UIViewAnimationState animationForLayer:forKey:forView:] + 720
2 UIKit 0x000000018a6c5df4 -[UIViewAnimationState actionForLayer:forKey:forView:] + 44
3 UIKit 0x000000018a689fec -[UIView(CALayerDelegate) actionForLayer:forKey:] + 140
4 QuartzCore 0x0000000189fd5378 -[CALayer actionForKey:] + 104
5 QuartzCore 0x0000000189fca92c actionForKey(CALayer*, CA::Transaction*, NSString*) + 100
6 QuartzCore 0x0000000189fca798 CA::Layer::begin_change(CA::Transaction*, unsigned int, objc_object*&) + 176
7 QuartzCore 0x0000000189fcd7f8 CA::Layer::setter(unsigned int, _CAValueType, void const*) + 160
8 QuartzCore 0x0000000189fd5304 -[CALayer setOpacity:] + 48
9 UIKit 0x000000018a689a40 -[UIView(Rendering) setAlpha:] + 112
10 MediaPlayer 0x0000000187f557b0 -[MPVolumeSlider _layoutForAvailableRoutes] + 1448
11 MediaPlayer 0x0000000187f5413c -[MPVolumeSlider layoutSubviews] + 80
12 UIKit 0x000000018a68d760 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 580
13 QuartzCore 0x0000000189fd5e1c -[CALayer layoutSublayers] + 152
14 QuartzCore 0x0000000189fd0884 CA::Layer::layout_if_needed(CA::Transaction*) + 320
15 UIKit 0x000000018a6a1f94 -[UIView(Hierarchy) layoutBelowIfNeeded] + 160
16 UIKit 0x000000018a6a7830 -[UISlider setValue:animated:] + 196
17 MediaPlayer 0x0000000187f5492c -[MPVolumeSlider volumeController:volumeValueDidChange:] + 92
18 MediaPlayer 0x0000000187fc7a00 -[MPVolumeController updateVolumeValue] + 260
19 MediaPlayer 0x0000000187f54284 -[MPVolumeSlider didMoveToSuperview] + 144
20 UIKit 0x000000018a68c2bc -[UIView(Hierarchy) _postMovedFromSuperview:] + 484
21 UIKit 0x000000018a6980b0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1792
22 MediaPlayer 0x0000000187f57528 -[MPVolumeView _createSubviews] + 264
23 MediaPlayer 0x0000000187f55fa8 -[MPVolumeView _initWithStyle:] + 240
24 MediaPlayer 0x0000000187f56034 -[MPVolumeView initWithFrame:style:] + 88
25 WebCore 0x0000000194ebd51c -[WebMediaSessionHelper allocateVolumeView] + 192
26 WebCore 0x0000000194ebd7f8 -[WebMediaSessionHelper initWithCallback:] + 468
27 WebCore 0x0000000194ebcbf8 WebCore::MediaSessionManageriOS::MediaSessionManageriOS() + 96
28 WebCore 0x0000000194ebcb68 WebCore::MediaSessionManager::sharedManager() + 56
29 WebCore 0x0000000194ebb66c WebCore::MediaSession::MediaSession(WebCore::MediaSessionClient&) + 44
30 WebCore 0x00000001949fb33c WebCore::HTMLMediaSession::create(WebCore::MediaSessionClient&) + 36
31 WebCore 0x00000001949e3c34 WebCore::HTMLMediaElement::HTMLMediaElement(WebCore::QualifiedName const&, WebCore::Document&, bool) + 1100
32 WebCore 0x0000000194a1d024 WebCore::HTMLVideoElement::create(WebCore::QualifiedName const&, WebCore::Document&, bool) + 68
33 WebCore 0x00000001949d0664 WebCore::videoConstructor(WebCore::QualifiedName const&, WebCore::Document&, WebCore::HTMLFormElement*, bool) + 92
34 WebCore 0x00000001949cf554 WebCore::HTMLElementFactory::createElement(WebCore::QualifiedName const&, WebCore::Document&, WebCore::HTMLFormElement*, bool) + 336
35 WebCore 0x00000001944af29c WebCore::HTMLDocument::createElement(WTF::AtomicString const&, int&) + 112
36 WebCore 0x00000001944af198 WebCore::jsDocumentPrototypeFunctionCreateElement(JSC::ExecState*) + 364
37 JavaScriptCore 0x00000001874a2fb0 llint_entry + 26160
38 JavaScriptCore 0x00000001874a2b0c llint_entry + 24972
39 JavaScriptCore 0x00000001874a29dc llint_entry + 24668
40 JavaScriptCore 0x000000018749c764 callToJavaScript + 308
41 JavaScriptCore 0x000000018740aac8 JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 48
42 JavaScriptCore 0x00000001871568d0 JSC::Interpreter::execute(JSC::ProgramExecutable*, JSC::ExecState*, JSC::JSObject*) + 7652
43 JavaScriptCore 0x000000018715497c JSC::evaluate(JSC::ExecState*, JSC::SourceCode const&, JSC::JSValue, JSC::JSValue*) + 476
44 WebCore 0x00000001950496b0 WebCore::ScriptController::evaluateInWorld(WebCore::ScriptSourceCode const&, WebCore::DOMWrapperWorld&) + 284
45 WebCore 0x00000001944d27c0 WebCore::ScriptController::evaluate(WebCore::ScriptSourceCode const&) + 52
46 WebCore 0x00000001944d2728 WebCore::ScriptElement::executeScript(WebCore::ScriptSourceCode const&) + 332
47 WebCore 0x000000019465639c WebCore::ScriptElement::execute(WebCore::CachedScript*) + 184
48 WebCore 0x000000019504f6e4 WebCore::ScriptRunner::timerFired(WebCore::Timer<WebCore::ScriptRunner>&) + 492
49 WebCore 0x00000001944a5560 WebCore::ThreadTimers::sharedTimerFiredInternal() + 148
50 WebCore 0x00000001944a54a4 WebCore::timerFired(__CFRunLoopTimer*, void*) + 36
51 CoreFoundation 0x0000000185c0812c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
52 CoreFoundation 0x0000000185c07ddc __CFRunLoopDoTimer + 888
53 CoreFoundation 0x0000000185c05828 __CFRunLoopRun + 1372
54 CoreFoundation 0x0000000185b312d4 CFRunLoopRunSpecific + 396
55 WebCore 0x000000019452c894 RunWebThread(void*) + 468
56 libsystem_pthread.dylib 0x0000000197ca7dc8 _pthread_body + 164
57 libsystem_pthread.dylib 0x0000000197ca7d24 _pthread_body
UIWebView load html contains audio or vedio label, will random crash. This is WebKit's bug when allocateVolumeView. Now i has fixed this bug.
see my answer

UIWebSelectSinglePicker crash

We receive some reports for crashes in UIWebSelectSinglePicker. We guess it's due to an empty datasource array. This occurs in a webview though. How can we work around this? would prefer a native only solution
edit
happens only on iphones, running both iOS7 and iOS8
1 CoreFoundation __exceptionPreprocess + 127
2 libobjc.A.dylib objc_exception_throw + 36
3 CoreFoundation -[__NSArrayM objectAtIndex:] + 228
4 UIKit -[UIWebSelectSinglePicker pickerView:didSelectRow:inComponent:] + 56
5 UIKit -[UIPickerView _sendSelectionChangedForComponent:notify:] + 90
6 UIKit -[UIPickerTableView _scrollingFinished] + 152
7 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 842
8 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 502
9 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 28
10 UIKit -[UIScrollView _smoothScrollWithUpdateTime:] + 208
11 QuartzCore CA::Display::DisplayLinkItem::dispatch() + 96
12 QuartzCore CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 364
13 IOMobileFramebuffer IOMobileFramebufferVsyncNotifyFunc + 88
14 IOKit IODispatchCalloutFromCFMessage + 254
15 CoreFoundation __CFMachPortPerform + 130
16 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
17 CoreFoundation __CFRunLoopDoSource1 + 344
18 CoreFoundation __CFRunLoopRun + 1606
19 CoreFoundation CFRunLoopRunSpecific + 474
20 CoreFoundation CFRunLoopRunInMode + 104
21 GraphicsServices GSEventRunModal + 134
22 UIKit UIApplicationMain + 1438
23 MYAPP main (main.m:16)
24 libdyld.dylib start + 0
I would guess this is related to another issue here on SO
There is an issue with the WebView and system controls triggered from HTML.
I think there is no link with UIWebSelectSinglePicker. I think you are trying to access to an object at an index outside the range of your array.
To prevent this you can add something like:
if(index < [self.myArray count] && [self.myArray count] > 0){
id myobject = [self.myArray objectAtIndex:index];
// do what you want here with your object
}
To debug this kind of issue and find where it happens, try to add a symbolic breakpoint:
Select the breakpoint navigator
click on "+"
"add symbolic breakpoint"
add "objectAtIndex" in the symbol field

iOS - Determining the cause of a crash (from a crash report) in _WebTryThreadLock

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.
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?
Web Thread - Crashed.
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
Main - Thread
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
It seems you are updating UI on the background thread, in your code add this line wherever you are updating your UI and you are fetching data on the background thread:
dispatch_async(dispatch_get_main_queue(), ^{
// Update data here
});
As soon as you, rather code feels that data is there on device and it's time to update the UI corresponding to new data then try and bring back main thread in action.
Hope it helps.

Resources