- if (gc->thread_refcount == 0)
- gc->currentDpy = dpy;
- __glXSetCurrentContext(gc);
- ret = gc->vtable->bind(gc, oldGC, draw, read);
+ /* Attempt to bind the context. We do this before mucking with
+ * gc and __glXSetCurrentContext to properly handle our state in
+ * case of an error.
+ *
+ * If an error occurs, set the Null context since we've already
+ * blown away our old context. The caller is responsible for
+ * figuring out how to handle setting a valid context.
+ */
+ if (gc->vtable->bind(gc, oldGC, draw, read) != Success) {
+ __glXSetCurrentContextNull();
+ __glXUnlock();
+ __glXSendError(dpy, GLXBadContext, None, X_GLXMakeContextCurrent,
+ False);
+ return GL_FALSE;
+ }
+