diff --git a/dll/opengl/opengl32/dllmain.c b/dll/opengl/opengl32/dllmain.c index 9d4ced2114c..dae16d28c96 100644 --- a/dll/opengl/opengl32/dllmain.c +++ b/dll/opengl/opengl32/dllmain.c @@ -9,6 +9,22 @@ #ifdef OPENGL32_USE_TLS DWORD OglTlsIndex = 0xFFFFFFFF; + +BOOL init_tls_data(void) +{ + struct Opengl32_ThreadData* ThreadData; + + ThreadData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ThreadData)); + if(!ThreadData) + return FALSE; + TlsSetValue(OglTlsIndex, ThreadData); + ThreadData->glDispatchTable = &StubTable.glDispatchTable; + ThreadData->hglrc = NULL; + ThreadData->hdc = NULL; + ThreadData->dc_data = NULL; + return TRUE; +} + #endif BOOL WINAPI @@ -30,14 +46,8 @@ DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved) /* no break */ case DLL_THREAD_ATTACH: #ifdef OPENGL32_USE_TLS - ThreadData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ThreadData)); - if(!ThreadData) + if (!init_tls_data()) return FALSE; - TlsSetValue(OglTlsIndex, ThreadData); - ThreadData->glDispatchTable = &StubTable.glDispatchTable; - ThreadData->hglrc = NULL; - ThreadData->hdc = NULL; - ThreadData->dc_data = NULL; #else NtCurrentTeb()->glTable = &StubTable.glDispatchTable; #endif // defined(OPENGL32_USE_TLS) diff --git a/dll/opengl/opengl32/opengl32.h b/dll/opengl/opengl32/opengl32.h index 68e5a86672c..0aadd6782a9 100644 --- a/dll/opengl/opengl32/opengl32.h +++ b/dll/opengl/opengl32/opengl32.h @@ -121,11 +121,22 @@ struct Opengl32_ThreadData }; C_ASSERT(FIELD_OFFSET(struct Opengl32_ThreadData, glDispatchTable) == 0); +/* dllmain.c */ +BOOL init_tls_data(void); + static inline void IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data) { struct Opengl32_ThreadData* thread_data = TlsGetValue(OglTlsIndex); + if (!thread_data) + { + OutputDebugStringA("Calling init_tls_data from IntMakeCurrent\n"); + if (!init_tls_data()) + OutputDebugStringA("init_tls_data failed, brace for impact...\n"); + + thread_data = TlsGetValue(OglTlsIndex); + } thread_data->hglrc = hglrc; thread_data->hdc = hdc;