https://git.reactos.org/?p=reactos.git;a=commitdiff;h=64d10228ee1fea0f118735d812cf6bed7fbac1c0

commit 64d10228ee1fea0f118735d812cf6bed7fbac1c0
Author: Mark Jansen <[email protected]>
AuthorDate: Sun Nov 5 21:24:31 2017 +0100

    [OPENGL32] Allocate thread data in IntMakeCurrent if it is not allocated 
yet.
    CORE-12232
---
 dll/opengl/opengl32/dllmain.c  | 24 +++++++++++++++++-------
 dll/opengl/opengl32/opengl32.h | 11 +++++++++++
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/dll/opengl/opengl32/dllmain.c b/dll/opengl/opengl32/dllmain.c
index 9d4ced2114..dae16d28c9 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 68e5a86672..0aadd6782a 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;

Reply via email to