Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Try to survive a failure return from eglMakeCurrent.
Browse files Browse the repository at this point in the history
Assume a failure in eglMakeCurrent occurs because the SurfaceView
surface has been destroyed.

See b/6257956 for an example of this failure happening during rotation
stress testing.

Change-Id: I4618703b5291aba3a3f0c6bd83c3435a67b97d33
  • Loading branch information
jackpal committed Mar 29, 2012
1 parent b0721d4 commit 7d73df8
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions opengl/java/android/opengl/GLSurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,7 @@ public void destroyContext(EGL10 egl, EGLDisplay display,
if (LOG_THREADS) {
Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
}
throw new RuntimeException("eglDestroyContext failed: "
+ EGLLogWrapper.getErrorString(egl.eglGetError()));
EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
}
}
}
Expand Down Expand Up @@ -1094,7 +1093,12 @@ public boolean createSurface() {
* the context is current and bound to a surface.
*/
if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
throwEglException("eglMakeCurrent");
/*
* Could not make the context current, probably because the underlying
* SurfaceView surface has been destroyed.
*/
logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
return false;
}

return true;
Expand Down Expand Up @@ -1134,7 +1138,7 @@ GL createGL() {
*/
public int swap() {
if (! mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
return mEgl.eglGetError();
return mEgl.eglGetError();
}
return EGL10.EGL_SUCCESS;
}
Expand Down Expand Up @@ -1180,14 +1184,23 @@ private void throwEglException(String function) {
throwEglException(function, mEgl.eglGetError());
}

private void throwEglException(String function, int error) {
String message = function + " failed: " + EGLLogWrapper.getErrorString(error);
public static void throwEglException(String function, int error) {
String message = formatEglError(function, error);
if (LOG_THREADS) {
Log.e("EglHelper", "throwEglException tid=" + Thread.currentThread().getId() + " " + message);
Log.e("EglHelper", "throwEglException tid=" + Thread.currentThread().getId() + " "
+ message);
}
throw new RuntimeException(message);
}

public static void logEglErrorAsWarning(String tag, String function, int error) {
Log.w(tag, formatEglError(function, error));
}

public static String formatEglError(String function, int error) {
return function + " failed: " + EGLLogWrapper.getErrorString(error);
}

private WeakReference<GLSurfaceView> mGLSurfaceViewWeakRef;
EGL10 mEgl;
EGLDisplay mEglDisplay;
Expand Down Expand Up @@ -1334,7 +1347,7 @@ private void guardedRun() throws InterruptedException {
}
}

// Have we lost the surface view surface?
// Have we lost the SurfaceView surface?
if ((! mHasSurface) && (! mWaitingForSurface)) {
if (LOG_SURFACE) {
Log.i("GLThread", "noticed surfaceView surface lost tid=" + getId());
Expand Down Expand Up @@ -1446,8 +1459,8 @@ private void guardedRun() throws InterruptedException {
Log.w("GLThread", "egl createSurface");
}
if (!mEglHelper.createSurface()) {
// Couldn't create a surface. Quit quietly.
break;
mSurfaceIsBad = true;
continue;
}
createEglSurface = false;
}
Expand Down Expand Up @@ -1502,12 +1515,10 @@ private void guardedRun() throws InterruptedException {
break;
default:
// Other errors typically mean that the current surface is bad,
// probably because the surfaceview surface has been destroyed,
// probably because the SurfaceView surface has been destroyed,
// but we haven't been notified yet.
// Log the error to help developers understand why rendering stopped.
Log.w("GLThread", "eglSwapBuffers error: " + swapError +
". Assume surfaceview surface is being destroyed. tid="
+ getId());
EglHelper.logEglErrorAsWarning("GLThread", "eglSwapBuffers", swapError);
mSurfaceIsBad = true;
break;
}
Expand Down

0 comments on commit 7d73df8

Please sign in to comment.