[vlc-devel] [PATCH] opengl: api: drain error in case of error

Alexandre Janniaux ajanni at videolabs.io
Wed Jan 27 17:13:45 UTC 2021


Otherwise, the error might be detected afterwards in an unrelated part
of the code, leading to potential failure or assertion depending on the
compilation options.

Indeed, an OpenGL call can lead to multiple errors and glGetError must
be called in loop, as mentioned by the documentation.

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetError.xhtml

> To allow for distributed implementations, there may be several error
> flags. If any single error flag has recorded an error, the value of
> that flag is returned and that flag is reset to GL_NO_ERROR when
> glGetError is called. If more than one flag has recorded an error,
> glGetError returns and clears an arbitrary error flag value. Thus,
> glGetError should always be called in a loop, until it returns
> GL_NO_ERROR, if all error flags are to be reset.
---
 modules/video_output/opengl/gl_api.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/modules/video_output/opengl/gl_api.c b/modules/video_output/opengl/gl_api.c
index 1264dde2a1..d990493832 100644
--- a/modules/video_output/opengl/gl_api.c
+++ b/modules/video_output/opengl/gl_api.c
@@ -163,6 +163,10 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
      */
     api->supports_multisample = version >= 3 && error == GL_NO_ERROR;
 
+    /* Drain the errors before continuing. */
+    while (error != GL_NO_ERROR)
+        error = api->vt.GetError();
+
 #ifdef USE_OPENGL_ES2
     api->is_gles = true;
     /* OpenGL ES 2 includes support for non-power of 2 textures by specification
-- 
2.30.0



More information about the vlc-devel mailing list