rem: if (context != NULL) { glgfx_context_select(context); }
context: struct glgfx_context* glgfx_monitor_createcontext(struct glgfx_monitor* monitor) {  struct glgfx_context* context;    if (monitor == NULL) {    errno = EINVAL;    return NULL;  }  context = calloc(1, sizeof (*context));  if (context == NULL) {    errno = ENOMEM;    return NULL;  }  context->extensions = g_hash_table_new(g_str_hash, g_str_equal);  if (context->extensions == NULL) {    glgfx_context_destroy(context);    errno = ENOMEM;    return NULL;  }  pthread_mutex_lock(&glgfx_mutex);  context->monitor = monitor;  context->glx_context = glXCreateContext(    monitor->display,    monitor->vinfo,    (monitor->main_context != NULL ? monitor->main_context->glx_context :     monitor->friend != NULL ? monitor->friend->main_context->glx_context : NULL),    True);  if (glXMakeCurrent(monitor->display, monitor->window, context->glx_context)) {    // Check that all the required extensions are present    if (check_extensions(context)) {      // Init all extensions we might use, if we haven't done so already      glgfx_glext_init();      glGenFramebuffersEXT(1, &context->fbo);      if (context->fbo != 0) {	// Setup a standard integer 2D coordinate system	glViewport(0, 0, monitor->mode.hdisplay, monitor->mode.vdisplay);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(0, monitor->mode.hdisplay, monitor->mode.vdisplay, 0, -1, 0);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	GLGFX_CHECKERROR();      }      else {	BUG("Unable to create framebuffer_object!\n");	glgfx_context_destroy(context);	context = NULL;	errno = ENOTSUP;      }    }    else {      // Required extensions missing      glgfx_context_destroy(context);      context = NULL;      errno = ENOTSUP;    }  }  else {    BUG("Unable to make GL context current!\n");    glgfx_context_destroy(context);    context = NULL;    errno = ENOTSUP;  }  // Make the newly created context active  if (context != NULL) {    glgfx_context_select(context);  }  pthread_mutex_unlock(&glgfx_mutex);  return context;}