From 3f49f5c15723bf974945adee00cc88f554643a44 Mon Sep 17 00:00:00 2001 From: dancho Date: Tue, 30 Jul 2024 10:46:49 -0700 Subject: [PATCH] Check for EGL_NO_SURFACE and similar in GlUtil `== null` does not check for equality with EGL_NO_SURFACE, EGL_NO_CONTEXT, or EGL_NO_DISPLAY. PiperOrigin-RevId: 657651835 --- .../main/java/androidx/media3/common/util/GlUtil.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java b/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java index 91f2d57332..dcf231e6f9 100644 --- a/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java +++ b/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java @@ -293,7 +293,7 @@ public final class GlUtil { sharedContext, contextAttributes, /* offset= */ 0); - if (eglContext == null) { + if (eglContext == null || eglContext.equals(EGL14.EGL_NO_CONTEXT)) { EGL14.eglTerminate(eglDisplay); throw new GlException( "eglCreateContext() failed to create a valid context. The device may not support EGL" @@ -778,13 +778,13 @@ public final class GlUtil { */ public static void destroyEglContext( @Nullable EGLDisplay eglDisplay, @Nullable EGLContext eglContext) throws GlException { - if (eglDisplay == null) { + if (eglDisplay == null || eglDisplay.equals(EGL14.EGL_NO_DISPLAY)) { return; } EGL14.eglMakeCurrent( eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); checkEglException("Error releasing context"); - if (eglContext != null) { + if (eglContext != null && !eglContext.equals(EGL14.EGL_NO_CONTEXT)) { EGL14.eglDestroyContext(eglDisplay, eglContext); checkEglException("Error destroying context"); } @@ -800,7 +800,10 @@ public final class GlUtil { */ public static void destroyEglSurface( @Nullable EGLDisplay eglDisplay, @Nullable EGLSurface eglSurface) throws GlException { - if (eglDisplay == null || eglSurface == null) { + if (eglDisplay == null || eglDisplay.equals(EGL14.EGL_NO_DISPLAY)) { + return; + } + if (eglSurface == null || eglSurface.equals(EGL14.EGL_NO_SURFACE)) { return; }