ROSGL_DeleteContext( GLRC *glrc )
{
/* unload icd */
- if (glrc->icd != NULL)
+ if ((glrc->icd != NULL) && !(InterlockedDecrement((LONG*)&glrc->icd->refcount)))
+ {
+ /* This is the last context, remove the ICD */
ROSGL_DeleteDCDataForICD( glrc->icd );
+ }
/* remove from list */
ROSGL_RemoveContext( glrc );
data = OPENGL32_processdata.dcdata_list;
while (data != NULL)
{
- if (data->hdc == hdc) /* found */
+ if ((data->hdc == hdc) || (WindowFromDC(data->hdc) == WindowFromDC(hdc))) /* found */
break;
data = data->next;
}
NULL) != NULL)
{
/* Too bad, somebody else was faster... */
- OPENGL32_UnloadICD(drvdata);
+ DBGTRACE("Uh, Someone beat you to it!\n");
}
}
}
/* FIXME: fallback? */
return NULL;
}
+
+ /* Don't forget to refcount it, icd will be released when last context is deleted */
+ InterlockedIncrement((LONG*)&icd->refcount);
+
+ if(!rosglGetPixelFormat(hdc))
+ {
+ ROSGL_DeleteContext(glrc);
+ SetLastError(ERROR_INVALID_PIXEL_FORMAT);
+ return NULL;
+ }
/* create context */
if (icd->DrvCreateLayerContext != NULL)
glrc->is_current = FALSE;
OPENGL32_threaddata->glrc = NULL;
}
+ else if ((GetObjectType(hdc) != OBJ_DC) && (GetObjectType(hdc) != OBJ_MEMDC))
+ {
+ DBGPRINT("Current context is NULL and requested HDC is invalid.\n");
+ SetLastError(ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
}
else
{