[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] gtk3: Delete created shader programs on GtkWidget.unrealize
From: |
Nikolas Nyby |
Subject: |
[PATCH] gtk3: Delete created shader programs on GtkWidget.unrealize |
Date: |
Wed, 15 May 2024 00:56:54 -0400 |
I'm not sure if the shaders created by init_shaders() are deleted
automatically when the widget's window is closed. This change
deletes them on the GtkWidget's unrealize event.
---
board3d/GLwidget.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/board3d/GLwidget.c b/board3d/GLwidget.c
index 95ad2650..feaef0e9 100644
--- a/board3d/GLwidget.c
+++ b/board3d/GLwidget.c
@@ -333,6 +333,19 @@ realize_event(GtkWidget* widget, const GLWidgetData*
glwData)
gtk_widget_queue_draw(widget);
}
+static void
+unrealize_event(GtkWidget* self, gpointer user_data)
+{
+ GLWidgetMakeCurrent(self);
+
+ if (glIsProgram(basicShader.shader)) {
+ glDeleteProgram(basicShader.shader);
+ }
+ if (glIsProgram(mainShader.shader)) {
+ glDeleteProgram(mainShader.shader);
+ }
+}
+
static void
resize_event(GtkGLArea* widget, gint UNUSED(width), gint UNUSED(height), const
GLWidgetData* glwData)
{
@@ -407,8 +420,10 @@ GtkWidget* GLWidgetCreate(RealizeCB realizeCB, ConfigureCB
configureCB, ExposeCB
glwData->configureCB = configureCB;
glwData->exposeCB = exposeCB;
- if (realizeCB != NULL)
+ if (realizeCB != NULL) {
g_signal_connect(G_OBJECT(pw), "realize",
G_CALLBACK(realize_event), glwData);
+ g_signal_connect(G_OBJECT(pw), "unrealize",
G_CALLBACK(unrealize_event), NULL);
+ }
if (configureCB != NULL)
g_signal_connect(G_OBJECT(pw), "resize",
G_CALLBACK(resize_event), glwData);
if (exposeCB != NULL)
--
2.34.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] gtk3: Delete created shader programs on GtkWidget.unrealize,
Nikolas Nyby <=