Skip to content

Commit

Permalink
Merge pull request #46 from elishacloud/RefCount-Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
crosire authored Sep 10, 2017
2 parents 80b66d4 + 6f6d859 commit 2412926
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 209 deletions.
11 changes: 0 additions & 11 deletions source/d3d8to9_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ static const D3DFORMAT AdapterFormats[] = {
D3DFMT_A1R5G5B5
};

IDirect3DDevice9 *pCurrentDeviceInterface = nullptr;
D3DPRESENT_PARAMETERS CurrentPresentParams;

// IDirect3D8
Direct3D8::Direct3D8(IDirect3D9 *ProxyInterface) :
ProxyInterface(ProxyInterface)
Expand Down Expand Up @@ -206,19 +203,11 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic

HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);

if (hr == D3DERR_DEVICELOST && pCurrentDeviceInterface)
{
pCurrentDeviceInterface->Reset(&CurrentPresentParams);
hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);
}

if (FAILED(hr))
{
return hr;
}

pCurrentDeviceInterface = DeviceInterface;
CopyMemory(&PresentParams, &CurrentPresentParams, sizeof(PresentParams));
*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);

return D3D_OK;
Expand Down
6 changes: 0 additions & 6 deletions source/d3d8to9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ struct VertexShaderInfo
Direct3DDevice8::Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, BOOL EnableZBufferDiscarding) :
D3D(d3d), ProxyInterface(ProxyInterface), ZBufferDiscarding(EnableZBufferDiscarding)
{
D3D->AddRef();
ProxyAddressLookupTable = new AddressLookupTable(this);
PaletteFlag = SupportsPalettes();
}
Direct3DDevice8::~Direct3DDevice8()
{
delete ProxyAddressLookupTable;
ProxyInterface->Release();
D3D->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DDevice8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -861,11 +858,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetTexture(DWORD Stage, Direct3DBaseT
*ppTexture = ProxyAddressLookupTable->FindAddress<Direct3DCubeTexture8>(CubeTextureInterface);
break;
default:
BaseTextureInterface->Release();
return D3DERR_INVALIDCALL;
}

BaseTextureInterface->Release();
}

return D3D_OK;
Expand Down
24 changes: 1 addition & 23 deletions source/d3d8to9_index_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
Direct3DIndexBuffer8::Direct3DIndexBuffer8(Direct3DDevice8 *Device, IDirect3DIndexBuffer9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DIndexBuffer8::~Direct3DIndexBuffer8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -51,19 +41,7 @@ ULONG STDMETHODCALLTYPE Direct3DIndexBuffer8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DIndexBuffer8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down
24 changes: 1 addition & 23 deletions source/d3d8to9_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
Direct3DSurface8::Direct3DSurface8(Direct3DDevice8 *Device, IDirect3DSurface9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DSurface8::~Direct3DSurface8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DSurface8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -50,19 +40,7 @@ ULONG STDMETHODCALLTYPE Direct3DSurface8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DSurface8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down
24 changes: 1 addition & 23 deletions source/d3d8to9_swap_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
Direct3DSwapChain8::Direct3DSwapChain8(Direct3DDevice8 *Device, IDirect3DSwapChain9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DSwapChain8::~Direct3DSwapChain8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -50,19 +40,7 @@ ULONG STDMETHODCALLTYPE Direct3DSwapChain8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DSwapChain8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::Present(const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
Expand Down
72 changes: 3 additions & 69 deletions source/d3d8to9_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
Direct3DTexture8::Direct3DTexture8(Direct3DDevice8 *Device, IDirect3DTexture9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DTexture8::~Direct3DTexture8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DTexture8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -52,19 +42,7 @@ ULONG STDMETHODCALLTYPE Direct3DTexture8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DTexture8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down Expand Up @@ -182,20 +160,10 @@ Direct3DCubeTexture8::Direct3DCubeTexture8(Direct3DDevice8 *device, IDirect3DCub
ProxyInterface(ProxyInterface),
Device(device)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DCubeTexture8::~Direct3DCubeTexture8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -225,19 +193,7 @@ ULONG STDMETHODCALLTYPE Direct3DCubeTexture8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DCubeTexture8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down Expand Up @@ -355,20 +311,10 @@ Direct3DVolumeTexture8::Direct3DVolumeTexture8(Direct3DDevice8 *device, IDirect3
ProxyInterface(ProxyInterface),
Device(device)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DVolumeTexture8::~Direct3DVolumeTexture8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -398,19 +344,7 @@ ULONG STDMETHODCALLTYPE Direct3DVolumeTexture8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DVolumeTexture8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down
24 changes: 1 addition & 23 deletions source/d3d8to9_vertex_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
Direct3DVertexBuffer8::Direct3DVertexBuffer8(Direct3DDevice8 *Device, IDirect3DVertexBuffer9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DVertexBuffer8::~Direct3DVertexBuffer8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -51,19 +41,7 @@ ULONG STDMETHODCALLTYPE Direct3DVertexBuffer8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DVertexBuffer8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down
24 changes: 1 addition & 23 deletions source/d3d8to9_volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
Direct3DVolume8::Direct3DVolume8(Direct3DDevice8 *Device, IDirect3DVolume9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
Device->AddRef();
Device->ProxyAddressLookupTable->SaveAddress(this, ProxyInterface);
}
Direct3DVolume8::~Direct3DVolume8()
{
if (CleanUpFlag)
{
Device->ProxyAddressLookupTable->DeleteAddress(this);
if (Active)
{
Active = false;
Device->Release();
}
}
}

HRESULT STDMETHODCALLTYPE Direct3DVolume8::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -50,19 +40,7 @@ ULONG STDMETHODCALLTYPE Direct3DVolume8::AddRef()
}
ULONG STDMETHODCALLTYPE Direct3DVolume8::Release()
{
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
if (Active)
{
Active = false;
Device->Release();
}
//delete this;
}

return LastRefCount;
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDevice(Direct3DDevice8 **ppDevice)
Expand Down
Loading

0 comments on commit 2412926

Please sign in to comment.