[OPENGL32] Allocate thread data in IntMakeCurrent if it is not allocated yet.

CORE-12232
This commit is contained in:
Mark Jansen 2017-11-05 21:24:31 +01:00
parent fa9ce98d8e
commit 64d10228ee
2 changed files with 28 additions and 7 deletions

View 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)

View 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;