From 9bcf411430cca69197a7756c1ce8ca925456cc93 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sat, 15 Dec 2012 06:55:33 +0000 Subject: [PATCH] Fix crash while initializing OpenGL context GL was crashing with a BadAlloc, this seems to be related to the Intel graphics drivers when using indirect rendering. Using a direct rendering context fixes the problem, however we can at least attempt both way if one or the other fails. --- src/gtkgl.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/gtkgl.c b/src/gtkgl.c index 6a62e86..af2c62b 100644 --- a/src/gtkgl.c +++ b/src/gtkgl.c @@ -56,6 +56,26 @@ void gtk_gl_disable(GtkWidget *widget) #elif defined(SYS_X11) #include #include +static gboolean gtk_gl_errors; +static int gtk_gl_handler(Display *xdisplay, XErrorEvent *xerror) +{ + gtk_gl_errors = TRUE; + return 0; +} +static GLXContext gtk_gl_create_context(Display *xdisplay, XVisualInfo *xvinfo, + GLXContext shared, Bool direct) +{ + gtk_gl_errors = FALSE; + XSync(xdisplay, False); + void *handler = XSetErrorHandler(gtk_gl_handler); + GLXContext context = glXCreateContext(xdisplay, xvinfo, shared, direct); + XSync(xdisplay, False); + XSetErrorHandler(handler); + + if (gtk_gl_errors) + return 0; + return context; +} void gtk_gl_enable(GtkWidget *widget) { g_debug("GtkGl: enable"); @@ -72,10 +92,20 @@ void gtk_gl_enable(GtkWidget *widget) GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None}; + XVisualInfo *xvinfo = glXChooseVisual(xdisplay, nscreen, attribs); if (!xvinfo) g_error("GtkGl: enable - unable to get valid OpenGL Visual"); - GLXContext context = glXCreateContext(xdisplay, xvinfo, NULL, True); + GLXContext context = 0; + if (!context) + context = gtk_gl_create_context(xdisplay, xvinfo, NULL, True); + if (!context) + context = gtk_gl_create_context(xdisplay, xvinfo, NULL, False); + if (!context) + g_error("Unable to create OpenGL context," + "possible graphics driver problem?"); + g_debug("GtkGl: direct rendering = %d\n", glXIsDirect(xdisplay, context)); + g_object_set_data(G_OBJECT(widget), "glcontext", context); /* Fix up colormap */ -- 2.43.2