diff --git a/reactos/dll/win32/opengl32/opengl32.c b/reactos/dll/win32/opengl32/opengl32.c index b9ae5a9cc18..24970ede722 100644 --- a/reactos/dll/win32/opengl32/opengl32.c +++ b/reactos/dll/win32/opengl32/opengl32.c @@ -521,11 +521,8 @@ OPENGL32_UnloadICD( GLDRIVERDATA *icd ) return FALSE; /* FIXME: do we have to expect such an error and handle it? */ } - icd->refcount--; - if (icd->refcount == 0) -// if (0) + if (--icd->refcount == 0) ret = OPENGL32_UnloadDriver( icd ); - /* FIXME: InitializeICD crashes when called a second time */ /* release mutex */ if (!ReleaseMutex( OPENGL32_processdata.driver_mutex )) diff --git a/reactos/dll/win32/opengl32/wgl.c b/reactos/dll/win32/opengl32/wgl.c index 2b211da5a7e..96be9621474 100644 --- a/reactos/dll/win32/opengl32/wgl.c +++ b/reactos/dll/win32/opengl32/wgl.c @@ -122,7 +122,7 @@ ROSGL_RemoveContext( GLRC *glrc ) */ static GLRC * -ROSGL_NewContext() +ROSGL_NewContext(void) { GLRC *glrc; @@ -136,6 +136,51 @@ ROSGL_NewContext() return glrc; } +/*! \brief Delete all GLDCDATA with this IDC + * + * \param icd [IN] Pointer to a ICD + */ +static +VOID +ROSGL_DeleteDCDataForICD( GLDRIVERDATA *icd ) +{ + GLDCDATA *p, **pptr; + + /* synchronize */ + if (WaitForSingleObject( OPENGL32_processdata.dcdata_mutex, INFINITE ) == + WAIT_FAILED) + { + DBGPRINT( "Error: WaitForSingleObject() failed (%d)", GetLastError() ); + return; + } + + p = OPENGL32_processdata.dcdata_list; + pptr = &OPENGL32_processdata.dcdata_list; + while (p != NULL) + { + if (p->icd == icd) + { + *pptr = p->next; + OPENGL32_UnloadICD( p->icd ); + + if (!HeapFree( GetProcessHeap(), 0, p )) + DBGPRINT( "Warning: HeapFree() on GLDCDATA failed (%d)", + GetLastError() ); + + p = *pptr; + } + else + { + pptr = &p->next; + p = p->next; + } + } + + /* release mutex */ + if (!ReleaseMutex( OPENGL32_processdata.dcdata_mutex )) + DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() ); +} + /*! \brief Delete a GL Context (GLRC) and remove it from the list * @@ -150,7 +195,7 @@ ROSGL_DeleteContext( GLRC *glrc ) { /* unload icd */ if (glrc->icd != NULL) - OPENGL32_UnloadICD( glrc->icd ); + ROSGL_DeleteDCDataForICD( glrc->icd ); /* remove from list */ ROSGL_RemoveContext( glrc );