Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird iOS UIWebView Crash called WTF Crash

I am using UIWebViews in some of the screens, because I need a perfect Html text parsing.

According to crash reports a huge number of crashes, called WTF Crash, occur on these screens. Here is a trace of that crash

Crashed: WebThread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000bbadbeef

Thread : Crashed: WebThread
0  JavaScriptCore                 0x184fd2710 WTFCrash + 72
1  JavaScriptCore                 0x184fd2708 WTFCrash + 64
2  WebCore                        0x1852b7d78 <redacted> + 362
3  WebCore                        0x1852b7bec <redacted> + 44
4  CoreFoundation                 0x1817d8588 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
5  CoreFoundation                 0x1817d632c __CFRunLoopDoObservers + 372
6  CoreFoundation                 0x1817d6674 __CFRunLoopRun + 696
7  CoreFoundation                 0x181705680 CFRunLoopRunSpecific + 384
8  WebCore                        0x1852b5998 <redacted> + 456
9  libsystem_pthread.dylib        0x18148bb28 <redacted> + 156
10 libsystem_pthread.dylib        0x18148ba8c _pthread_start + 154
11 libsystem_pthread.dylib        0x181489028 thread_start + 4

There is no OS version, or device relation on this crash.

I am not doing anything fancy on using UIWebView as well. It is added to nib like every other component, and in the implementation file I use it like the following

self.webView.scrollView.scrollEnabled = NO;
self.webView.scrollView.bounces = NO;
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];
self.webView.delegate = self;
[self.webView loadHTMLString:htmlString baseURL:nil];

Any suggestions on how to solve WTF Crash?

Edit: Here is how htmlString looks like

Printing description of htmlString:
<html><body style="font-family:HelveticaNeue; font-size:10; background-color:#E5E4E4; text-align:left; color:#696969 ">test string</body></html>
like image 571
mamba4ever Avatar asked Feb 01 '16 10:02

mamba4ever


1 Answers

I don't know how you are creating your UIWebView. But I was having a similiar issue with a WTFCrash and I was able to solve it by making sure that the UIWebView was being created on the main thread:

- (void)createWebView{
    if (![NSThread isMainThread]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self createWebView];
        });
        return;
    }
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    //Rest of my code
}
like image 111
Jan Avatar answered Sep 29 '22 12:09

Jan