From 30f45ce5f7d639dd5a0b60f544b3535e3bc2105d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 22 Sep 2009 15:15:47 +0100 Subject: [gl] Handle an absent visual. If we cannot find the correct visual for the fbconfig, return an error instead of crashing. The difference is subtle, granted. --- src/cairo-gl-surface.c | 8 ++++++++ src/cairo-glx-context.c | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c index e73646ae..17bf4bc5 100644 --- a/src/cairo-gl-surface.c +++ b/src/cairo-gl-surface.c @@ -61,6 +61,11 @@ static const cairo_gl_context_t _nil_context = { CAIRO_STATUS_NO_MEMORY }; +static const cairo_gl_context_t _nil_context__invalid_format = { + CAIRO_REFERENCE_COUNT_INVALID, + CAIRO_STATUS_INVALID_FORMAT +}; + static cairo_bool_t _cairo_surface_is_gl (cairo_surface_t *surface) { return surface->backend == &_cairo_gl_surface_backend; @@ -72,6 +77,9 @@ _cairo_gl_context_create_in_error (cairo_status_t status) if (status == CAIRO_STATUS_NO_MEMORY) return (cairo_gl_context_t *) &_nil_context; + if (status == CAIRO_STATUS_INVALID_FORMAT) + return (cairo_gl_context_t *) &_nil_context__invalid_format; + ASSERT_NOT_REACHED; return NULL; } diff --git a/src/cairo-glx-context.c b/src/cairo-glx-context.c index 18fe2297..b442a1fc 100644 --- a/src/cairo-glx-context.c +++ b/src/cairo-glx-context.c @@ -99,8 +99,6 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy) Window win = None; int cnt; - cairo_status_t status = CAIRO_STATUS_SUCCESS; - /* Create a dummy window created for the target GLX context that we can * use to query the available GL/GLX extensions. */ @@ -114,6 +112,9 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy) vi = glXGetVisualFromFBConfig (dpy, config[0]); XFree (config); + if (unlikely (vi == NULL)) + return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); + cmap = XCreateColormap (dpy, RootWindow (dpy, vi->screen), vi->visual, @@ -136,7 +137,7 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy) } *dummy = win; - return status; + return CAIRO_STATUS_SUCCESS; } cairo_gl_context_t * -- cgit v1.2.3