@@ -779,8 +779,7 @@ public void destroyContext(EGL10 egl, EGLDisplay display,
779779 if (LOG_THREADS ) {
780780 Log .i ("DefaultContextFactory" , "tid=" + Thread .currentThread ().getId ());
781781 }
782- throw new RuntimeException ("eglDestroyContext failed: "
783- + EGLLogWrapper .getErrorString (egl .eglGetError ()));
782+ EglHelper .throwEglException ("eglDestroyContex" , egl .eglGetError ());
784783 }
785784 }
786785 }
@@ -1094,7 +1093,12 @@ public boolean createSurface() {
10941093 * the context is current and bound to a surface.
10951094 */
10961095 if (!mEgl .eglMakeCurrent (mEglDisplay , mEglSurface , mEglSurface , mEglContext )) {
1097- throwEglException ("eglMakeCurrent" );
1096+ /*
1097+ * Could not make the context current, probably because the underlying
1098+ * SurfaceView surface has been destroyed.
1099+ */
1100+ logEglErrorAsWarning ("EGLHelper" , "eglMakeCurrent" , mEgl .eglGetError ());
1101+ return false ;
10981102 }
10991103
11001104 return true ;
@@ -1134,7 +1138,7 @@ GL createGL() {
11341138 */
11351139 public int swap () {
11361140 if (! mEgl .eglSwapBuffers (mEglDisplay , mEglSurface )) {
1137- return mEgl .eglGetError ();
1141+ return mEgl .eglGetError ();
11381142 }
11391143 return EGL10 .EGL_SUCCESS ;
11401144 }
@@ -1180,14 +1184,23 @@ private void throwEglException(String function) {
11801184 throwEglException (function , mEgl .eglGetError ());
11811185 }
11821186
1183- private void throwEglException (String function , int error ) {
1184- String message = function + " failed: " + EGLLogWrapper . getErrorString ( error );
1187+ public static void throwEglException (String function , int error ) {
1188+ String message = formatEglError ( function , error );
11851189 if (LOG_THREADS ) {
1186- Log .e ("EglHelper" , "throwEglException tid=" + Thread .currentThread ().getId () + " " + message );
1190+ Log .e ("EglHelper" , "throwEglException tid=" + Thread .currentThread ().getId () + " "
1191+ + message );
11871192 }
11881193 throw new RuntimeException (message );
11891194 }
11901195
1196+ public static void logEglErrorAsWarning (String tag , String function , int error ) {
1197+ Log .w (tag , formatEglError (function , error ));
1198+ }
1199+
1200+ public static String formatEglError (String function , int error ) {
1201+ return function + " failed: " + EGLLogWrapper .getErrorString (error );
1202+ }
1203+
11911204 private WeakReference <GLSurfaceView > mGLSurfaceViewWeakRef ;
11921205 EGL10 mEgl ;
11931206 EGLDisplay mEglDisplay ;
@@ -1334,7 +1347,7 @@ private void guardedRun() throws InterruptedException {
13341347 }
13351348 }
13361349
1337- // Have we lost the surface view surface?
1350+ // Have we lost the SurfaceView surface?
13381351 if ((! mHasSurface ) && (! mWaitingForSurface )) {
13391352 if (LOG_SURFACE ) {
13401353 Log .i ("GLThread" , "noticed surfaceView surface lost tid=" + getId ());
@@ -1446,8 +1459,8 @@ private void guardedRun() throws InterruptedException {
14461459 Log .w ("GLThread" , "egl createSurface" );
14471460 }
14481461 if (!mEglHelper .createSurface ()) {
1449- // Couldn't create a surface. Quit quietly.
1450- break ;
1462+ mSurfaceIsBad = true ;
1463+ continue ;
14511464 }
14521465 createEglSurface = false ;
14531466 }
@@ -1502,12 +1515,10 @@ private void guardedRun() throws InterruptedException {
15021515 break ;
15031516 default :
15041517 // Other errors typically mean that the current surface is bad,
1505- // probably because the surfaceview surface has been destroyed,
1518+ // probably because the SurfaceView surface has been destroyed,
15061519 // but we haven't been notified yet.
15071520 // Log the error to help developers understand why rendering stopped.
1508- Log .w ("GLThread" , "eglSwapBuffers error: " + swapError +
1509- ". Assume surfaceview surface is being destroyed. tid="
1510- + getId ());
1521+ EglHelper .logEglErrorAsWarning ("GLThread" , "eglSwapBuffers" , swapError );
15111522 mSurfaceIsBad = true ;
15121523 break ;
15131524 }
0 commit comments