[OPENGL32]
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 11 Mar 2011 18:17:34 +0000 (18:17 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Fri, 11 Mar 2011 18:17:34 +0000 (18:17 +0000)
  - 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
reactos/dll/win32/opengl32/opengl32.c
reactos/dll/win32/opengl32/wgl.c

index eaab125..2619f34 100644 (file)
@@ -18,6 +18,8 @@ typedef struct tagICDTable
     PROC       dispatch_table[812]; /*!< Table containing \a num_funcs pointers to OpenGL functions */
 } ICDTable, *PICDTable;
 
     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 */
 #endif /* OPENGL32_PRIVATE_ICDTABLE_H */
 
 /* EOF */
index 1d5330a..e3c5602 100644 (file)
@@ -34,7 +34,7 @@ OPENGL32_ThreadAttach( void )
 
     dispatchTable = (PROC*)HeapAlloc( GetProcessHeap(),
                                       HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
 
     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" );
     if (dispatchTable == NULL)
     {
         DBGPRINT( "Error: Couldn't allocate GL dispatch table" );
@@ -84,6 +84,7 @@ OPENGL32_ThreadDetach( void )
                       GetLastError() );
         lpData = NULL;
     }
                       GetLastError() );
         lpData = NULL;
     }
+    TlsSetValue( OPENGL32_tls, NULL );
 
     if (teb->glTable != NULL)
     {
 
     if (teb->glTable != NULL)
     {
index aadf186..9584ba5 100644 (file)
@@ -454,13 +454,12 @@ ROSGL_SetContextCallBack( const ICDTable *table )
         /* save table */
         size = sizeof (PROC) * table->num_funcs;
         memcpy( tebTable, table->dispatch_table, size );
         /* 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" );
     }
     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 */
     }
 
     /* put in empty functions as long as we dont have a fallback */