{"record":{"id":"e9a014e35776ae9d","repo":"google/ExoPlayer","slug":"eglcreatecontext-failed-to-create-a-valid-contex","errorCode":null,"errorMessage":"eglCreateContext() failed to create a valid context. The device may not support EGL version {version}","messagePattern":"eglCreateContext\\(\\) failed to create a valid context\\. The device may not support EGL version (.+?)","errorType":"exception","errorClass":"GlException","httpStatus":null,"severity":"error","filePath":"library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java","lineNumber":728,"sourceCode":"      checkGlError();\n      return eglDisplay;\n    }\n\n    @DoNotInline\n    public static EGLContext createEglContext(\n        EGLContext sharedContext, EGLDisplay eglDisplay, int version, int[] configAttributes)\n        throws GlException {\n      int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, version, EGL14.EGL_NONE};\n      EGLContext eglContext =\n          EGL14.eglCreateContext(\n              eglDisplay,\n              getEglConfig(eglDisplay, configAttributes),\n              sharedContext,\n              contextAttributes,\n              /* offset= */ 0);\n      if (eglContext == null) {\n        EGL14.eglTerminate(eglDisplay);\n        throw new GlException(\n            \"eglCreateContext() failed to create a valid context. The device may not support EGL\"\n                + \" version \"\n                + version);\n      }\n      checkGlError();\n      return eglContext;\n    }\n\n    @DoNotInline\n    public static EGLSurface createEglSurface(\n        EGLDisplay eglDisplay, Object surface, int[] configAttributes, int[] windowAttributes)\n        throws GlException {\n      EGLSurface eglSurface =\n          EGL14.eglCreateWindowSurface(\n              eglDisplay,\n              getEglConfig(eglDisplay, configAttributes),\n              surface,\n              windowAttributes,","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java#L710-L746","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nEGLContext ctx = GlUtil.createEglContext(sharedContext, eglDisplay, /* version= */ 3,\n    GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_1010102); // throws on GLES2-only device\n// after\nboolean hasGles3 = deviceSupportsGles3(); // check via FeatureFlags or temp context glGetString\nEGLContext ctx = GlUtil.createEglContext(sharedContext, eglDisplay,\n    hasGles3 ? 3 : 2,\n    hasGles3 ? GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_1010102\n             : GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_8888);","handlingStrategy":"fallback","validationCode":"boolean gles3 = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))\n    .getDeviceConfigurationInfo().reqGlEsVersion >= 0x30000;","typeGuard":null,"tryCatchPattern":"try { ctx = GlUtil.createEglContext(shared, display, 3, attrs1010102); }\ncatch (GlException e) { ctx = GlUtil.createEglContext(shared, display, 2, GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_8888); }","preventionTips":["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"],"tags":["opengl","egl","gles3","device-support","context"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}