{"record":{"id":"448eb7e85d8fdcbb","repo":"wasabeef/android-gpuimage","slug":"function-failed-error","errorCode":null,"errorMessage":"<function> failed: <error>","messagePattern":"<function> failed: <error>","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/jp/co/cyberagent/android/gpuimage/GLTextureView.java","lineNumber":1097,"sourceCode":"                eglContext = null;\n            }\n            if (eglDisplay != null) {\n                egl.eglTerminate(eglDisplay);\n                eglDisplay = null;\n            }\n        }\n\n        private void throwEglException(String function) {\n            throwEglException(function, egl.eglGetError());\n        }\n\n        public static void throwEglException(String function, int error) {\n            String message = formatEglError(function, error);\n            if (LOG_THREADS) {\n                Log.e(\"EglHelper\",\n                        \"throwEglException tid=\" + Thread.currentThread().getId() + \" \" + message);\n            }\n            throw new RuntimeException(message);\n        }\n\n        public static void logEglErrorAsWarning(String tag, String function, int error) {\n            Log.w(tag, formatEglError(function, error));\n        }\n\n        public static String formatEglError(String function, int error) {\n            return function + \" failed: \" + error;\n        }\n\n        private WeakReference<GLTextureView> glTextureViewWeakRef;\n        EGL10 egl;\n        EGLDisplay eglDisplay;\n        EGLSurface eglSurface;\n        EGLConfig eglConfig;\n        EGLContext eglContext;\n    }\n","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/wasabeef/android-gpuimage/blob/ceea576ec931c2968431ad46f1fb2e6d68a542e2/library/src/main/java/jp/co/cyberagent/android/gpuimage/GLTextureView.java#L1079-L1115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log the formatted error name (formatEglError) to identify the exact EGL code and fix accordingly","Catch the RuntimeException around eglCreateWindowSurface/eglMakeCurrent and retry with a fresh EglHelper","Stop rendering when the Surface is destroyed/abandoned (onSurfaceDestroyed -> requestExitAndWait)","Avoid sharing EGL contexts across threads without eglReleaseThread; release surface before destroying the view"],"exampleFix":"// before\nthrowEglException(\"eglCreateWindowSurface\", error); // crashes app\n// after\ntry {\n    surface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, holder, null);\n} catch (RuntimeException e) {\n    Log.e(TAG, \"surface creation failed, recreating EglHelper\", e);\n    finish(); start(); // recreate EGL state\n}","handlingStrategy":"try-catch","validationCode":"// Check surface validity before creating the EGL surface\nif (holder.getSurface() == null || !holder.getSurface().isValid()) { return; }","typeGuard":null,"tryCatchPattern":"// catch (RuntimeException e) { parse e.getLocalizedMessage() for EGL_BAD_ALLOC / EGL_BAD_NATIVE_WINDOW; recreate EglHelper or stop rendering }","preventionTips":["Stop the GL thread on onSurfaceDestroyed before the Surface is reclaimed","Release EGL surfaces and contexts promptly; releaseThread on thread exit","Watch for EGL_BAD_ALLOC under memory pressure; reduce texture sizes","Never call EGL surface APIs from multiple threads concurrently"],"tags":["egl","android","opengl","surface-lifecycle","egl-bad-error"],"backgroundTag":"http-error-response","analyzedSha":"ceea576ec931c2968431ad46f1fb2e6d68a542e2","analyzedAt":"2026-09-11T16:56:13.742Z","contentChangedAt":"2026-09-11T16:56:13.742Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}