iOS WebView Webcore JavaScriptCore crash崩潰解決辦法

表現

這類webcore崩潰一般出現gpusSubmitDataBuffers 、gpus_ReturnNotPermittedKillClient、OpenGLES等日誌。

1
Application received signal SIGSEGV
2
(null)
3
((
4
    0 CoreFoundation 0x0000000184e20f74 <redacted> + 148
5
    1 libobjc.A.dylib 0x000000019a307f80 objc_exception_throw + 56
6
    2 CoreFoundation 0x0000000184e20ea4 <redacted> + 0
7
    3 ECalendar 0x0000000100d25f20 ECalendar + 13279008
8
    4 libsystem_platform.dylib 0x000000019ad0593c _sigtramp + 52
9
    5 libGPUSupportMercury.dylib 0x000000018f826ec4 gpusSubmitDataBuffers + 172
10
    6 GLEngine 0x000000018833ad84 gliBindViewES + 108
11
    7 OpenGLES 0x0000000188347bf4 <redacted> + 436
12
    8 WebCore 0x00000001976bdf84 <redacted> + 116
13
    9 WebCore 0x0000000197fca350 <redacted> + 148
14
    10 WebCore 0x0000000197fc9ca8 <redacted> + 780
15
    11 WebCore 0x0000000197fc7804 <redacted> + 12
16
    12 WebCore 0x00000001976e90ec <redacted> + 232
17
    13 WebCore 0x00000001976e91d4 <redacted> + 12
18
    14 JavaScriptCore 0x00000001868ce484 <redacted> + 348
19
    15 JavaScriptCore 0x000000018677aa78 <redacted> + 104
20
    16 JavaScriptCore 0x00000001864523a0 <redacted> + 40
21
    17 JavaScriptCore 0x000000018644db1c <redacted> + 220
22
    18 CoreFoundation 0x0000000184dd8c9c <redacted> + 28
23
    19 CoreFoundation 0x0000000184dd8940 <redacted> + 884
24
    20 CoreFoundation 0x0000000184dd6054 <redacted> + 1520
25
    21 CoreFoundation 0x0000000184d04dc0 CFRunLoopRunSpecific + 384
26
    22 WebCore 0x0000000197235aa0 <redacted> + 456
27
    23 libsystem_pthread.dylib 0x000000019ad0bb3c <redacted> + 156
28
    24 libsystem_pthread.dylib 0x000000019ad0baa0 <redacted> + 0
29
    25 libsystem_pthread.dylib 0x000000019ad09030 thread_start + 4
30
)

說明

當應用退出到後臺時如果程序仍然在調用OpenGL的API,那麼程序會被強制終結。文檔沒有說明系統版本問題,但是在iOS8以上的系統上測試確實是必現的一個crash,但是由於是在退出後crash(其實也就是下一次進入應用是重新啓動了,有可能在剛打開的時候會閃現一下之前的畫面),用戶不易察覺。奇怪的是iOS7系統並不會出現這個問題,並且在後臺所有的crash日誌裏也都100%是iOS8以上的用戶報告了這一crash。

解決辦法:

在webview對象或者使用webview的對象裏添加如下代碼塊:

typedef void (*CallFuc)(id, SEL, BOOL);
typedef BOOL (*GetFuc)(id, SEL);
- (BOOL)webView:(UIWebView*)view enableGL:(BOOL)bEnable
{
    BOOL bRet = NO;
    do
    {
        Ivar internalVar = class_getInstanceVariable([view class], "_internal");
        if (!internalVar)
        {
            NSLog(@"enable GL _internal invalid!");
            break;
        }
        
        UIWebViewInternal* internalObj = object_getIvar(view, internalVar);
        Ivar browserVar = class_getInstanceVariable(object_getClass(internalObj), "browserView");
        if (!browserVar)
        {
            NSLog(@"enable GL browserView invalid!");
            break;
        }
        
        id webbrowser = object_getIvar(internalObj, browserVar);
        Ivar webViewVar = class_getInstanceVariable(object_getClass(webbrowser), "_webView");
        if (!webViewVar)
        {
            NSLog(@"enable GL _webView invalid!");
            break;
        }
        
        id webView = object_getIvar(webbrowser, webViewVar);
        if (!webView)
        {
            NSLog(@"enable GL webView obj nil!");
        }
        
        if(object_getClass(webView) != NSClassFromString(@"WebView"))
        {
            NSLog(@"enable GL webView not WebView!");
            break;
        }
        
        SEL selector = NSSelectorFromString(@"_setWebGLEnabled:");
        IMP impSet = [webView methodForSelector:selector];
        CallFuc func = (CallFuc)impSet;
        func(webView, selector, bEnable);
        
        SEL selectorGet = NSSelectorFromString(@"_webGLEnabled");
        IMP impGet = [webView methodForSelector:selectorGet];
        GetFuc funcGet = (GetFuc)impGet;
        BOOL val = funcGet(webView, selector);
        
        bRet = (val == bEnable);
        
    }while(NO);
    
    return bRet;
}
  • 方法1:在webview loadRequest之前,調用方法,設置webview的 enableGL爲NO。
  • 方法2:檢測APP進入前臺和後臺,進入前臺設置enableGL爲YES,後臺設置enableGL爲NO。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章