{
if (!_wcsicmp( driver, icd->driver_name )) /* found */
{
- icd->refcount++;
-
/* release mutex */
if (!ReleaseMutex( OPENGL32_processdata.driver_mutex ))
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
/* not found - try to load */
icd = OPENGL32_LoadDriver( driver );
- if (icd != NULL)
- icd->refcount = 1;
/* release mutex */
if (!ReleaseMutex( OPENGL32_processdata.driver_mutex ))
return FALSE; /* FIXME: do we have to expect such an error and handle it? */
}
- if (--icd->refcount == 0)
+ if (icd->refcount == 0)
ret = OPENGL32_UnloadDriver( icd );
/* release mutex */
WCHAR DriverName[256]; /*!< Driver name */
} OPENGL_INFO, *POPENGL_INFO;
-
/*! \brief Append OpenGL Rendering Context (GLRC) to list
*
* \param glrc [IN] Pointer to GLRC to append to list
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 );
NULL) != NULL)
{
/* Too bad, somebody else was faster... */
- OPENGL32_UnloadICD(drvdata);
+ DBGTRACE("ICD is already set!\n");
}
}
}
/* FIXME: fallback? */
return NULL;
}
+ /* Don't forget to refcount it, icd will be released when last context is deleted */
+ InterlockedIncrement((LONG*)&icd->refcount);
+
/* create context */
if (icd->DrvCreateLayerContext != NULL)