From c86778464737dae494a5c788f55eabc1eed85e48 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 17 May 2017 15:15:36 +0100 Subject: [PATCH] Don't assign function ptrs in gl*GetProcAddress if we have one already * In theory, gl*GetProcAddress can return different function pointers at different times, but in practice this does not happen. Also we have many more problems if there was an implementation that did this. * In reality what can happen if we don't preserve existing function pointers is that any call to gl*GetProcAddress will overwrite required emulated functions for e.g. EXT_dsa if the implementation doesn't support the extension but does return valid pointers for the query. --- renderdoc/driver/gl/gl_hooks_linux_shared.cpp | 14 ++++++++------ renderdoc/driver/gl/gl_hooks_win32.cpp | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/renderdoc/driver/gl/gl_hooks_linux_shared.cpp b/renderdoc/driver/gl/gl_hooks_linux_shared.cpp index 8816c6bc4..7ee9dc806 100644 --- a/renderdoc/driver/gl/gl_hooks_linux_shared.cpp +++ b/renderdoc/driver/gl/gl_hooks_linux_shared.cpp @@ -43,17 +43,19 @@ Threading::CriticalSection &GetGLLock() return glLock; } -#define HookInit(function) \ - if(!strcmp(func, STRINGIZE(function))) \ - { \ - GL.function = (CONCAT(function, _hooktype))realFunc; \ - return (void *)&CONCAT(function, _renderdoc_hooked); \ +#define HookInit(function) \ + if(!strcmp(func, STRINGIZE(function))) \ + { \ + if(GL.function == NULL) \ + GL.function = (CONCAT(function, _hooktype))realFunc; \ + return (void *)&CONCAT(function, _renderdoc_hooked); \ } #define HookExtension(funcPtrType, function) \ if(!strcmp(func, STRINGIZE(function))) \ { \ - GL.function = (funcPtrType)realFunc; \ + if(GL.function == NULL) \ + GL.function = (funcPtrType)realFunc; \ return (void *)&CONCAT(function, _renderdoc_hooked); \ } diff --git a/renderdoc/driver/gl/gl_hooks_win32.cpp b/renderdoc/driver/gl/gl_hooks_win32.cpp index ca855c3d4..86b136f25 100644 --- a/renderdoc/driver/gl/gl_hooks_win32.cpp +++ b/renderdoc/driver/gl/gl_hooks_win32.cpp @@ -44,14 +44,15 @@ #define HookExtension(funcPtrType, function) \ if(!strcmp(func, STRINGIZE(function))) \ { \ - glhooks.GL.function = (funcPtrType)realFunc; \ + if(glhooks.GL.function == NULL) \ + glhooks.GL.function = (funcPtrType)realFunc; \ return (PROC)&glhooks.CONCAT(function, _hooked); \ } #define HookExtensionAlias(funcPtrType, function, alias) \ if(!strcmp(func, STRINGIZE(alias))) \ { \ - if(OpenGLHook::glhooks.GL.function == NULL) \ + if(glhooks.GL.function == NULL) \ glhooks.GL.function = (funcPtrType)realFunc; \ return (PROC)&glhooks.CONCAT(function, _hooked); \ }