表现
这类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。