wasabeef/android-gpuimage · error · RuntimeException

failed

Error message

<function> failed: <error>

What it means

throwEglException formats and rethrows any EGL function failure as RuntimeException('<function> failed: <error description>') via formatEglError, which maps the EGL error int (0x3000-0x300D) to names like EGL_BAD_ALLOC, EGL_BAD_CONFIG, EGL_BAD_MATCH. It is the generic escape hatch for EGL calls in createSurface/makeCurrent/swap that aren't explicitly guarded.

Solutions

  1. Log the formatted error name (formatEglError) to identify the exact EGL code and fix accordingly
  2. Catch the RuntimeException around eglCreateWindowSurface/eglMakeCurrent and retry with a fresh EglHelper
  3. Stop rendering when the Surface is destroyed/abandoned (onSurfaceDestroyed -> requestExitAndWait)
  4. Avoid sharing EGL contexts across threads without eglReleaseThread; release surface before destroying the view

Example fix

// before
throwEglException("eglCreateWindowSurface", error); // crashes app
// after
try {
    surface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, holder, null);
} catch (RuntimeException e) {
    Log.e(TAG, "surface creation failed, recreating EglHelper", e);
    finish(); start(); // recreate EGL state
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Check surface validity before creating the EGL surface
if (holder.getSurface() == null || !holder.getSurface().isValid()) { return; }

Try / catch

// catch (RuntimeException e) { parse e.getLocalizedMessage() for EGL_BAD_ALLOC / EGL_BAD_NATIVE_WINDOW; recreate EglHelper or stop rendering }

Prevention

When it happens

Trigger: Any of eglCreateWindowSurface, eglCreateContext, eglMakeCurrent, eglSwapBuffers, eglDestroySurface returning false/error != EGL_SUCCESS — e.g. eglCreateWindowSurface on an invalid/abandoned Surface, eglMakeCurrent with a context already current on another thread (EGL_BAD_ACCESS), EGL_BAD_ALLOC under memory pressure.

Common situations: Surface destroyed while GL thread still renders (EGL_BAD_NATIVE_WINDOW), GPU memory exhaustion (EGL_BAD_ALLOC), mismatched config/context pairing (EGL_BAD_MATCH), setting surface size on a dead SurfaceHolder.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of wasabeef/android-gpuimage@ceea576ec9 (2026-09-11). Data as JSON: /api/errors/448eb7e85d8fdcbb. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/jp/co/cyberagent/android/gpuimage/GLTextureView.java:1097

                eglContext = null;
            }
            if (eglDisplay != null) {
                egl.eglTerminate(eglDisplay);
                eglDisplay = null;
            }
        }

        private void throwEglException(String function) {
            throwEglException(function, egl.eglGetError());
        }

        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);
            }
            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: " + error;
        }

        private WeakReference<GLTextureView> glTextureViewWeakRef;
        EGL10 egl;
        EGLDisplay eglDisplay;
        EGLSurface eglSurface;
        EGLConfig eglConfig;
        EGLContext eglContext;
    }

View on GitHub (pinned to ceea576ec9)