From e8cdc22245835cb17c82a9dc1525ffa793e34541 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 12 Sep 2016 19:47:26 +0200 Subject: vo_opengl: better behavior in GL error corner cases If the shader fails to compile, and assertion could trigger in gl_sc_gen_shader_and_reset() due to the code trying to recreate the shader every time, and re-appending the uniforms every time. Just reset the uniform array to fix this. Some disturbed GL drivers might not return anything for glGetShaderiv() if the GL state got "lost", so initialize variables just for additional robustness. --- video/out/opengl/utils.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'video') diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c index 72a748a82d..c97aebaa88 100644 --- a/video/out/opengl/utils.c +++ b/video/out/opengl/utils.c @@ -780,9 +780,9 @@ static void compile_attach_shader(struct gl_shader_cache *sc, GLuint program, GLuint shader = gl->CreateShader(type); gl->ShaderSource(shader, 1, &source, NULL); gl->CompileShader(shader); - GLint status; + GLint status = 0; gl->GetShaderiv(shader, GL_COMPILE_STATUS, &status); - GLint log_length; + GLint log_length = 0; gl->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length); int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DEBUG) : MSGL_ERR; @@ -820,9 +820,9 @@ static void link_shader(struct gl_shader_cache *sc, GLuint program) { GL *gl = sc->gl; gl->LinkProgram(program); - GLint status; + GLint status = 0; gl->GetProgramiv(program, GL_LINK_STATUS, &status); - GLint log_length; + GLint log_length = 0; gl->GetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length); int pri = status ? (log_length > 1 ? MSGL_V : MSGL_DEBUG) : MSGL_ERR; @@ -980,6 +980,7 @@ void gl_sc_gen_shader_and_reset(struct gl_shader_cache *sc) // build vertex shader from vao and cache the locations of the uniform variables if (!entry->gl_shader) { entry->gl_shader = create_program(sc, vert->start, frag->start); + entry->num_uniforms = 0; for (int n = 0; n < sc->num_uniforms; n++) { struct sc_cached_uniform un = { .loc = gl->GetUniformLocation(entry->gl_shader, -- cgit v1.2.3