From 97ac18d3d2c8c072cd51237cf5348e21c396da99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 10 Jul 2020 21:36:47 +0200 Subject: [PATCH] Add proper disposing to colered triangle graphics example --- src/shimatta-opengl-colored-triangle.c | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/shimatta-opengl-colored-triangle.c b/src/shimatta-opengl-colored-triangle.c index 7660c62..b965662 100644 --- a/src/shimatta-opengl-colored-triangle.c +++ b/src/shimatta-opengl-colored-triangle.c @@ -69,14 +69,41 @@ static void draw_with_model_matrix(ShimattaOpenglGraphics *self, mat4 m, mat4 n) draw(self); } +static void shimatta_opengl_colored_triangle_dispose(GObject *obj) +{ + ShimattaOpenglColoredTriangle *self; + ShimattaOpenglColoredTrianglePrivate *priv; + + self = SHIMATTA_OPENGL_COLORED_TRIANGLE(obj); + priv = shimatta_opengl_colored_triangle_get_instance_private(self); + + if (priv->vao) { + glDeleteVertexArrays(1, &priv->vao); + priv->vao = 0; + } + + if (priv->vbo) { + glDeleteBuffers(1, &priv->vbo); + priv->vbo = 0; + } + + g_clear_object(&priv->prog); + + G_OBJECT_CLASS(shimatta_opengl_colored_triangle_parent_class)->dispose(obj); +} + void shimatta_opengl_colored_triangle_class_init(ShimattaOpenglColoredTriangleClass *klass) { ShimattaOpenglGraphicsClass *gclass; + GObjectClass *oclass; + gclass = SHIMATTA_OPENGL_GRAPHICS_CLASS(klass); + oclass = G_OBJECT_CLASS(klass); gclass->draw = draw; gclass->realize = realize; gclass->draw_with_model_matrix = draw_with_model_matrix; + oclass->dispose = shimatta_opengl_colored_triangle_dispose; } void shimatta_opengl_colored_triangle_init(ShimattaOpenglColoredTriangle *self)