gl: Fix implicit leaking of shader object

According to OpenGL spec, a shader object will only be flagged
for deletion unless it has been detached; when a program object
is deleted, those shader objects attached to it will be detached
but not deleted unless they have already been flagged for deletion.

So we shall detach a shader object before it is deleted, and delete
it before the program object is deleted best.
This commit is contained in:
xndcn 2020-12-29 22:29:37 +08:00
parent 108933b655
commit 34ffdc6e3f
4 changed files with 9 additions and 5 deletions

View File

@ -787,6 +787,8 @@ gtk_gears_realize (GtkWidget *widget)
glLinkProgram(program);
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
g_debug ("program info: %s\n", msg);
glDetachShader (program, v);
glDetachShader (program, f);
glDeleteShader (v);
glDeleteShader (f);

View File

@ -107,6 +107,9 @@ make_program (GdkGLContextProgram *program,
glLinkProgram (program->program);
glDetachShader (program->program, vertex_shader);
glDetachShader (program->program, fragment_shader);
glDeleteShader (vertex_shader);
glDeleteShader (fragment_shader);

View File

@ -232,6 +232,8 @@ gsk_gl_shader_builder_create_program (GskGLShaderBuilder *self,
glBindAttribLocation (program_id, 0, "aPosition");
glBindAttribLocation (program_id, 1, "vUv");
glLinkProgram (program_id);
glDetachShader (program_id, vertex_id);
glDetachShader (program_id, fragment_id);
glGetProgramiv (program_id, GL_LINK_STATUS, &status);
if (status == GL_FALSE)
@ -252,14 +254,9 @@ gsk_gl_shader_builder_create_program (GskGLShaderBuilder *self,
glDeleteProgram (program_id);
program_id = -1;
goto out;
}
glDetachShader (program_id, vertex_id);
glDeleteShader (vertex_id);
glDetachShader (program_id, fragment_id);
glDeleteShader (fragment_id);
out:

View File

@ -787,6 +787,8 @@ gtk_gears_realize (GtkWidget *widget)
glLinkProgram(program);
glGetProgramInfoLog(program, sizeof msg, NULL, msg);
g_print ("program info: %s\n", msg);
glDetachShader (program, v);
glDetachShader (program, f);
glDeleteShader (v);
glDeleteShader (f);