From 70451a60ce221f2c4a3863b6e275e4ec1444bb5a Mon Sep 17 00:00:00 2001 From: Kissaki Date: Sat, 16 May 2015 11:44:01 +0200 Subject: Fix #1637 application crashes on Mumble exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * When unloading the overlay DLL freeD3D9Hook was called *after* unloading the DLL. This is incorrect. ** For applications that actually use D3D and we inject into, the DLL is never unloaded because we hold a refernce to it ourselves. So in this case, the problematic code is never executed. ** When not actually injecting, the DLL will be unloaded, and then the function freeD3D9Hook is called which is from that DLL. ** As we’re executing code in undefined space which previously held the function, this may or may not crash. * Remove the freeD3D9Hook function ** The function freeD3D9Hook just resets some fields to NULL and a flag to false. As the DLL is unloaded anyway, these are never used again. Hence, we can just remove it altogether (rather than just calling it before unloading). --- overlay/d3d9.cpp | 19 ------------------- overlay/lib.cpp | 2 -- overlay/lib.h | 2 -- 3 files changed, 23 deletions(-) (limited to 'overlay') diff --git a/overlay/d3d9.cpp b/overlay/d3d9.cpp index 82ca25df6..e31608a01 100644 --- a/overlay/d3d9.cpp +++ b/overlay/d3d9.cpp @@ -1010,25 +1010,6 @@ static void hookD3D9(HMODULE hD3D, bool preonly) { } } -void freeD3D9Hook(HMODULE hModule) { - HMODULE hD3D = GetModuleHandle("D3D9.DLL"); - if (bHooked && !hD3D) { - ods("D3D9: Freeing hooks for module %p", hModule); - - hhCreateDevice.reset(); - hhCreateDeviceEx.reset(); - hhReset.reset(); - hhResetEx.reset(); - hhAddRef.reset(); - hhRelease.reset(); - hhPresent.reset(); - hhPresentEx.reset(); - hhSwapPresent.reset(); - - bHooked = false; - } -} - extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() { if (! d3dd) return; diff --git a/overlay/lib.cpp b/overlay/lib.cpp index 9358212c0..9f63771dd 100644 --- a/overlay/lib.cpp +++ b/overlay/lib.cpp @@ -396,8 +396,6 @@ static BOOL WINAPI MyFreeLibrary(HMODULE hModule) { BOOL r = oFreeLibrary(hModule); hhFree.inject(); - freeD3D9Hook(hModule); - return r; } diff --git a/overlay/lib.h b/overlay/lib.h index 8e63be62a..d86fa803b 100644 --- a/overlay/lib.h +++ b/overlay/lib.h @@ -136,8 +136,6 @@ extern void checkDXGI11Hook(bool preonly = false); extern void checkD3D9Hook(bool preonly = false); // From opengl.cpp extern void checkOpenGLHook(); -// From d3d9.cpp -extern void freeD3D9Hook(HMODULE hModule); // From d3d9.cpp extern Direct3D9Data *d3dd; -- cgit v1.2.3