diff options
author | xndcn <xndchn@gmail.com> | 2020-12-29 22:29:37 +0800 |
---|---|---|
committer | xndcn <xndchn@gmail.com> | 2020-12-29 23:50:45 +0800 |
commit | 34ffdc6e3f5f1548ac2ded575cdd0e391cf9b66a (patch) | |
tree | 50b474041b78a60fa37c2eb09754bbb19d844ef0 | |
parent | 108933b655160efc4a9795906d01b81f78ddb62c (diff) | |
download | gtk+-34ffdc6e3f5f1548ac2ded575cdd0e391cf9b66a.tar.gz |
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.
-rw-r--r-- | demos/gtk-demo/gtkgears.c | 2 | ||||
-rw-r--r-- | gdk/gdkgl.c | 3 | ||||
-rw-r--r-- | gsk/gl/gskglshaderbuilder.c | 7 | ||||
-rw-r--r-- | tests/gtkgears.c | 2 |
4 files changed, 9 insertions, 5 deletions
diff --git a/demos/gtk-demo/gtkgears.c b/demos/gtk-demo/gtkgears.c index ba52ddd1b0..1463cbb6b5 100644 --- a/demos/gtk-demo/gtkgears.c +++ b/demos/gtk-demo/gtkgears.c @@ -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); diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c index 56dce18333..5ebd2138d8 100644 --- a/gdk/gdkgl.c +++ b/gdk/gdkgl.c @@ -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); diff --git a/gsk/gl/gskglshaderbuilder.c b/gsk/gl/gskglshaderbuilder.c index 1a4ddc301b..75aef60e7d 100644 --- a/gsk/gl/gskglshaderbuilder.c +++ b/gsk/gl/gskglshaderbuilder.c @@ -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: diff --git a/tests/gtkgears.c b/tests/gtkgears.c index 5f5686c883..2ece67dcf9 100644 --- a/tests/gtkgears.c +++ b/tests/gtkgears.c @@ -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); |