From 0cc06c7b45e2c8c0192981e53889aedb45489998 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Fri, 11 Mar 2011 18:17:34 +0000 Subject: [PATCH] [OPENGL32] - use well defined macro instead of weird pointer calculation - reset thread specific data on a thread detach call Fixes crash in heroes 3 and probably others svn path=/trunk/; revision=51019 --- reactos/dll/win32/opengl32/icdtable.h | 2 ++ reactos/dll/win32/opengl32/opengl32.c | 3 ++- reactos/dll/win32/opengl32/wgl.c | 5 ++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/reactos/dll/win32/opengl32/icdtable.h b/reactos/dll/win32/opengl32/icdtable.h index eaab125ca47..2619f34632d 100644 --- a/reactos/dll/win32/opengl32/icdtable.h +++ b/reactos/dll/win32/opengl32/icdtable.h @@ -18,6 +18,8 @@ typedef struct tagICDTable PROC dispatch_table[812]; /*!< Table containing \a num_funcs pointers to OpenGL functions */ } ICDTable, *PICDTable; +#define DISPATCH_TABLE_SIZE 812*sizeof(PROC) + #endif /* OPENGL32_PRIVATE_ICDTABLE_H */ /* EOF */ diff --git a/reactos/dll/win32/opengl32/opengl32.c b/reactos/dll/win32/opengl32/opengl32.c index 1d5330a411b..e3c56026e72 100644 --- a/reactos/dll/win32/opengl32/opengl32.c +++ b/reactos/dll/win32/opengl32/opengl32.c @@ -34,7 +34,7 @@ OPENGL32_ThreadAttach( void ) dispatchTable = (PROC*)HeapAlloc( GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, - sizeof (((ICDTable *)(0))->dispatch_table) ); + DISPATCH_TABLE_SIZE ); if (dispatchTable == NULL) { DBGPRINT( "Error: Couldn't allocate GL dispatch table" ); @@ -84,6 +84,7 @@ OPENGL32_ThreadDetach( void ) GetLastError() ); lpData = NULL; } + TlsSetValue( OPENGL32_tls, NULL ); if (teb->glTable != NULL) { diff --git a/reactos/dll/win32/opengl32/wgl.c b/reactos/dll/win32/opengl32/wgl.c index aadf186e9ac..9584ba5b362 100644 --- a/reactos/dll/win32/opengl32/wgl.c +++ b/reactos/dll/win32/opengl32/wgl.c @@ -454,13 +454,12 @@ ROSGL_SetContextCallBack( const ICDTable *table ) /* save table */ size = sizeof (PROC) * table->num_funcs; memcpy( tebTable, table->dispatch_table, size ); - memset( tebTable + table->num_funcs, 0, - sizeof (table->dispatch_table) - size ); + memset( tebTable + table->num_funcs, 0, DISPATCH_TABLE_SIZE - size ); } else { DBGPRINT( "Unsetting current context" ); - memset( tebTable, 0, sizeof (table->dispatch_table) ); + memset( tebTable, 0, DISPATCH_TABLE_SIZE ); } /* put in empty functions as long as we dont have a fallback */ -- 2.17.1