Skip to content

Commit 3534e13

Browse files
ChrisCraikAndroid (Google) Code Review
authored andcommitted
Merge "Avoid crash if onDetachedFromWindow called after destroy" into jb-dev
2 parents 2d243bc + 9e08012 commit 3534e13

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

core/java/android/webkit/WebViewClassic.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,11 +2069,20 @@ public void destroy() {
20692069
}
20702070

20712071
private void destroyImpl() {
2072-
int drawGLFunction = nativeGetDrawGLFunction(mNativeClass);
20732072
ViewRootImpl viewRoot = mWebView.getViewRootImpl();
2074-
Log.d(LOGTAG, String.format("destroyImpl, functor %x, viewroot == null %b, isHWAccel %b",
2075-
drawGLFunction, (viewRoot == null),
2076-
mWebView.isHardwareAccelerated()));
2073+
if (viewRoot != null) {
2074+
Log.e(LOGTAG, "Error: WebView.destroy() called while still attached!");
2075+
}
2076+
2077+
if (mWebView.isHardwareAccelerated()) {
2078+
int drawGLFunction = nativeGetDrawGLFunction(mNativeClass);
2079+
if (drawGLFunction != 0 && viewRoot != null) {
2080+
// functor should have been detached in onDetachedFromWindow, do
2081+
// additionally here for safety
2082+
viewRoot.detachFunctor(drawGLFunction);
2083+
}
2084+
}
2085+
20772086
mCallbackProxy.blockMessages();
20782087
clearHelpers();
20792088
if (mListBoxDialog != null) {
@@ -5301,12 +5310,9 @@ public void onDetachedFromWindow() {
53015310

53025311
updateHwAccelerated();
53035312

5304-
int drawGLFunction = nativeGetDrawGLFunction(mNativeClass);
5305-
ViewRootImpl viewRoot = mWebView.getViewRootImpl();
5306-
Log.d(LOGTAG, String.format("destroyImpl, functor %x, viewroot == null %b, isHWAccel %b",
5307-
drawGLFunction, (viewRoot == null),
5308-
mWebView.isHardwareAccelerated()));
53095313
if (mWebView.isHardwareAccelerated()) {
5314+
int drawGLFunction = nativeGetDrawGLFunction(mNativeClass);
5315+
ViewRootImpl viewRoot = mWebView.getViewRootImpl();
53105316
if (drawGLFunction != 0 && viewRoot != null) {
53115317
viewRoot.detachFunctor(drawGLFunction);
53125318
}

libs/hwui/OpenGLRenderer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ void OpenGLRenderer::resume() {
262262
}
263263

264264
void OpenGLRenderer::detachFunctor(Functor* functor) {
265-
ALOGD("opengl renderer %p detaching functor %p", this, functor);
266265
mFunctors.remove(functor);
267266
}
268267

@@ -310,7 +309,7 @@ status_t OpenGLRenderer::invokeFunctors(Rect& dirty) {
310309

311310
status_t OpenGLRenderer::callDrawGLFunction(Functor* functor, Rect& dirty) {
312311
interrupt();
313-
mFunctors.remove(functor);
312+
detachFunctor(functor);
314313

315314
if (mDirtyClip) {
316315
setScissorFromClip();

0 commit comments

Comments
 (0)