google/ExoPlayer · error · GlException
eglCreateContext() failed to create a valid context. The dev
Error message
eglCreateContext() failed to create a valid context. The device may not support EGL version {version} What it means
Thrown by GlUtil.Api17.createEglContext (reached from GlUtil.createEglContext) when android.opengl.EGL14.eglCreateContext returns null for the requested client version and config attributes. A null return means EGL could not create a context of that GLES version (commonly GLES 3.0 requested via version=3) with the chosen config — the message explicitly suggests the device may not support that EGL/GLES version. The display is terminated before throwing, since it cannot be reused.
Source
Thrown at library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java:728
checkGlError();
return eglDisplay;
}
@DoNotInline
public static EGLContext createEglContext(
EGLContext sharedContext, EGLDisplay eglDisplay, int version, int[] configAttributes)
throws GlException {
int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, version, EGL14.EGL_NONE};
EGLContext eglContext =
EGL14.eglCreateContext(
eglDisplay,
getEglConfig(eglDisplay, configAttributes),
sharedContext,
contextAttributes,
/* offset= */ 0);
if (eglContext == null) {
EGL14.eglTerminate(eglDisplay);
throw new GlException(
"eglCreateContext() failed to create a valid context. The device may not support EGL"
+ " version "
+ version);
}
checkGlError();
return eglContext;
}
@DoNotInline
public static EGLSurface createEglSurface(
EGLDisplay eglDisplay, Object surface, int[] configAttributes, int[] windowAttributes)
throws GlException {
EGLSurface eglSurface =
EGL14.eglCreateWindowSurface(
eglDisplay,
getEglConfig(eglDisplay, configAttributes),
surface,
windowAttributes,View on GitHub (pinned to dd430f7053)
Solutions
- Detect capability up front and fall back to GLES 2.0: query the device's supported version (from EGLConfig renderable type / glGetString(GL_VERSION) on a temp context) and pick version 2 when 3 is unavailable
- Fall back from the 10-bit path: if the 1010102 config/context fails, retry with RGBA_8888 + version 2 and an SDR (tone-mapped) pipeline
- Ensure you release EGL contexts/surfaces you own (GlUtil.destroyContext) so context creation does not exhaust driver limits
- On emulators, enable host GPU passthrough or test on a physical device supporting GLES 3.0
Example fix
// before
EGLContext ctx = GlUtil.createEglContext(sharedContext, eglDisplay, /* version= */ 3,
GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_1010102); // throws on GLES2-only device
// after
boolean hasGles3 = deviceSupportsGles3(); // check via FeatureFlags or temp context glGetString
EGLContext ctx = GlUtil.createEglContext(sharedContext, eglDisplay,
hasGles3 ? 3 : 2,
hasGles3 ? GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_1010102
: GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_8888); Defensive patterns
Strategy: fallback
Validate before calling
boolean gles3 = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
.getDeviceConfigurationInfo().reqGlEsVersion >= 0x30000; Try / catch
try { ctx = GlUtil.createEglContext(shared, display, 3, attrs1010102); }
catch (GlException e) { ctx = GlUtil.createEglContext(shared, display, 2, GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_8888); } Prevention
- Check reqGlEsVersion / EGL extension strings before requesting version 3 contexts
- Destroy EGL contexts you create; leaking them exhausts driver limits
- Prefer GlUtil.createEglContext's defaults; only override version when you know the device supports it
When it happens
Trigger: Requesting EGL_CONTEXT_CLIENT_VERSION 3 (used by RGBA_1010102 / 16-bit float / HDR pipelines) on devices whose driver only supports GLES 2.0; requesting a 10-bit config (EGL_CONFIG_ATTRIBUTES_RGBA_1010102) not exposed by the device's EGL implementation; passing a sharedContext from an incompatible context version; or EGL resources exhausted (too many live contexts).
Common situations: Transformer/effects HDR export or PQ/HLG editing on budget/older devices and some emulators lacking GLES3; apps mixing GLSurfaceView contexts with ExoPlayer-created contexts incorrectly; long-running sessions leaking EGL contexts until creation fails.
Related errors
- eglChooseConfig failed.
- Unsupported color transfer: {colorTransfer}
- No call to setSamplerTexId() before bind.
- Unexpected uniform type: {type}
- glError: {gluErrorString(error)}
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/e9a014e35776ae9d.
Report an issue: GitHub.