Skip to content
Permalink
Browse files

Fix #1637 application crashes on Mumble exit

* 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).
  • Loading branch information...
Kissaki committed May 16, 2015
1 parent 57740e7 commit 70451a60ce221f2c4a3863b6e275e4ec1444bb5a
Showing with 0 additions and 23 deletions.
  1. +0 −19 overlay/d3d9.cpp
  2. +0 −2 overlay/lib.cpp
  3. +0 −2 overlay/lib.h
@@ -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;
@@ -396,8 +396,6 @@ static BOOL WINAPI MyFreeLibrary(HMODULE hModule) {
BOOL r = oFreeLibrary(hModule);
hhFree.inject();

freeD3D9Hook(hModule);

return r;
}

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

0 comments on commit 70451a6

Please sign in to comment.
You can’t perform that action at this time.