Skip to content

Commit 9e08012

Browse files
committed
Avoid crash if onDetachedFromWindow called after destroy
This also removes the temporary logging from commit f8dafa1. bug:6535911 Change-Id: Icf1d0438b349a0e92e7d9cefed57a252eed2b9b0
1 parent f8dafa1 commit 9e08012

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
@@ -250,7 +250,6 @@ void OpenGLRenderer::resume() {
250250
}
251251

252252
void OpenGLRenderer::detachFunctor(Functor* functor) {
253-
ALOGD("opengl renderer %p detaching functor %p", this, functor);
254253
mFunctors.remove(functor);
255254
}
256255

@@ -303,7 +302,7 @@ status_t OpenGLRenderer::invokeFunctors(Rect& dirty) {
303302

304303
status_t OpenGLRenderer::callDrawGLFunction(Functor* functor, Rect& dirty) {
305304
interrupt();
306-
mFunctors.remove(functor);
305+
detachFunctor(functor);
307306

308307
if (mDirtyClip) {
309308
setScissorFromClip();

0 commit comments

Comments
 (0)