[OPENGL32] Allocate thread data in IntMakeCurrent if it is not allocated yet.
authorMark Jansen <mark.jansen@reactos.org>
Sun, 5 Nov 2017 20:24:31 +0000 (21:24 +0100)
committerMark Jansen <mark.jansen@reactos.org>
Fri, 17 Nov 2017 18:34:06 +0000 (19:34 +0100)
CORE-12232

dll/opengl/opengl32/dllmain.c
dll/opengl/opengl32/opengl32.h

index 9d4ced2..dae16d2 100644 (file)
@@ -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)
index 68e5a86..0aadd67 100644 (file)
@@ -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;