demo/glarea: Check errors on GtkGLArea

We should not call OpenGL API if GtkGLArea is in an error state.

https://bugzilla.gnome.org/show_bug.cgi?id=746746
This commit is contained in:
Emmanuele Bassi 2015-03-25 15:20:36 +00:00
parent fae3eaffcd
commit 721134b008

View File

@ -220,6 +220,9 @@ realize (GtkWidget *widget)
{ {
gtk_gl_area_make_current (GTK_GL_AREA (widget)); gtk_gl_area_make_current (GTK_GL_AREA (widget));
if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
return;
init_buffers (&position_buffer, NULL); init_buffers (&position_buffer, NULL);
init_shaders (&program, &mvp_location); init_shaders (&program, &mvp_location);
} }
@ -230,6 +233,9 @@ unrealize (GtkWidget *widget)
{ {
gtk_gl_area_make_current (GTK_GL_AREA (widget)); gtk_gl_area_make_current (GTK_GL_AREA (widget));
if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
return;
glDeleteBuffers (1, &position_buffer); glDeleteBuffers (1, &position_buffer);
glDeleteProgram (program); glDeleteProgram (program);
} }
@ -271,6 +277,9 @@ static gboolean
render (GtkGLArea *area, render (GtkGLArea *area,
GdkGLContext *context) GdkGLContext *context)
{ {
if (gtk_gl_area_get_error (area) != NULL)
return FALSE;
/* Clear the viewport */ /* Clear the viewport */
glClearColor (0.5, 0.5, 0.5, 1.0); glClearColor (0.5, 0.5, 0.5, 1.0);
glClear (GL_COLOR_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT);