GraphicsCapture: Fix crash when D3D9 device changes

The D3D9 device can terminate and reinitialize during games, so don't
just blindly store a pointer to a device that may no longer exist.
master
jp9000 2016-07-17 23:54:10 -07:00
parent 0a80ca1b12
commit 4f43d2f201
1 changed files with 15 additions and 2 deletions

View File

@ -1063,14 +1063,27 @@ HRESULT STDMETHODCALLTYPE D3D9PresentEx(IDirect3DDevice9Ex *device, CONST RECT*
HRESULT STDMETHODCALLTYPE D3D9SwapPresent(IDirect3DSwapChain9 *swap, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags)
{
IDirect3DDevice9 *device = nullptr;
#if OLDHOOKS
d3d9SwapPresent.Unhook();
#endif
RUNEVERYRESET logOutput << CurrentTimeString() << "D3D9SwapPresent called" << endl;
if(!presentRecurse)
DoD3D9DrawStuff((IDirect3DDevice9*)lpCurrentDevice);
if(!presentRecurse) {
HRESULT hr = swap->GetDevice(&device);
if (SUCCEEDED(hr))
device->Release();
if(lpCurrentDevice == NULL && !bTargetAcquired)
{
lpCurrentDevice = device;
bTargetAcquired = true;
}
if(lpCurrentDevice == device)
DoD3D9DrawStuff(device);
}
presentRecurse++;