From 801b10caff9e3c01ac8486d00f8f3ae77b0bea6c Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Fri, 23 Aug 2024 15:43:14 -0700 Subject: [PATCH] Fix debug build issue #291 --- Dllmain/BuildNo.rc | 2 +- d3d9/IDirect3D9Ex.h | 2 +- d3d9/IDirect3DDevice9Ex.cpp | 16 ++++++---------- d3d9/IDirect3DDevice9Ex.h | 18 ++++++++++++++---- d3d9/IDirect3DSwapChain9Ex.h | 2 +- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index bb4164ab..6004a450 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7107 +#define BUILD_NUMBER 7108 diff --git a/d3d9/IDirect3D9Ex.h b/d3d9/IDirect3D9Ex.h index c6025669..529cdb1f 100644 --- a/d3d9/IDirect3D9Ex.h +++ b/d3d9/IDirect3D9Ex.h @@ -25,7 +25,7 @@ class m_IDirect3D9Ex : public IDirect3D9Ex, public AddressLookupTableD3d9Object public: m_IDirect3D9Ex(LPDIRECT3D9EX pDirect3D, REFIID DeviceID) : ProxyInterface(pDirect3D), WrapperID(DeviceID) { - LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ")"); + LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ") " << WrapperID); if (WrapperID == IID_IDirect3D9Ex) { diff --git a/d3d9/IDirect3DDevice9Ex.cpp b/d3d9/IDirect3DDevice9Ex.cpp index 5a590783..57855922 100644 --- a/d3d9/IDirect3DDevice9Ex.cpp +++ b/d3d9/IDirect3DDevice9Ex.cpp @@ -31,20 +31,13 @@ struct TABLEMAP { std::vector AddressDeviceMap; +// Add device to map void AddToAddressDeviceMap(m_IDirect3DDevice9Ex* Device, AddressLookupTableD3d9* ProxyAddressLookupTable) { - // Check if device already exists in the map - for (auto &entry : AddressDeviceMap) - { - if (entry.Device == Device) - { - return; - } - } - // Add device to map if not already in the map AddressDeviceMap.push_back({ Device, ProxyAddressLookupTable }); } +// Remove device from the map void RemoveFromAddressDeviceMap(m_IDirect3DDevice9Ex* Device, AddressLookupTableD3d9* ProxyAddressLookupTable) { // Remove device from the map @@ -2455,7 +2448,10 @@ HRESULT m_IDirect3DDevice9Ex::GetDisplayModeEx(THIS_ UINT iSwapChain, D3DDISPLAY void m_IDirect3DDevice9Ex::ReInitDevice() { #ifdef ENABLE_DEBUGOVERLAY - DOverlay.Setup(DeviceDetails.DeviceWindow, ProxyInterface); + if (IsWindow(DeviceDetails.DeviceWindow)) + { + DOverlay.Setup(DeviceDetails.DeviceWindow, ProxyInterface); + } #endif // Get screen size diff --git a/d3d9/IDirect3DDevice9Ex.h b/d3d9/IDirect3DDevice9Ex.h index 198aad5c..6c86fddb 100644 --- a/d3d9/IDirect3DDevice9Ex.h +++ b/d3d9/IDirect3DDevice9Ex.h @@ -53,7 +53,7 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex, public AddressLookupTabl public: m_IDirect3DDevice9Ex(LPDIRECT3DDEVICE9EX pDevice, m_IDirect3D9Ex* pD3D, REFIID DeviceID) : ProxyInterface(pDevice), m_pD3DEx(pD3D), WrapperID(DeviceID) { - LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ")"); + LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ") " << WrapperID); if (WrapperID == IID_IDirect3DDevice9Ex) { @@ -74,14 +74,19 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex, public AddressLookupTabl } void SetProxyLookupTable(AddressLookupTableD3d9* LookupTable) { - ProxyAddressLookupTable = LookupTable; + if (!ProxyAddressLookupTable) + { + ProxyAddressLookupTable = LookupTable; - ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); + ProxyAddressLookupTable->SaveAddress(this, ProxyInterface); - AddToAddressDeviceMap(this, ProxyAddressLookupTable); + AddToAddressDeviceMap(this, ProxyAddressLookupTable); + } } void SetDeviceDetails(DEVICEDETAILS& NewDeviceDetails) { + HWND LastDeviceWindow = DeviceDetails.DeviceWindow; + DeviceDetails = NewDeviceDetails; // Check for SSAA @@ -90,6 +95,11 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex, public AddressLookupTabl { SetSSAA = true; } + + if (DeviceDetails.DeviceWindow != LastDeviceWindow) + { + ReInitDevice(); + } } AddressLookupTableD3d9* ProxyAddressLookupTable = nullptr; diff --git a/d3d9/IDirect3DSwapChain9Ex.h b/d3d9/IDirect3DSwapChain9Ex.h index c01cd22d..8e2ae18d 100644 --- a/d3d9/IDirect3DSwapChain9Ex.h +++ b/d3d9/IDirect3DSwapChain9Ex.h @@ -14,7 +14,7 @@ class m_IDirect3DSwapChain9Ex : public IDirect3DSwapChain9Ex, public AddressLook m_IDirect3DSwapChain9Ex(LPDIRECT3DSWAPCHAIN9EX pSwapChain9, m_IDirect3DDevice9Ex* pDevice, REFIID DeviceID) : ProxyInterface(pSwapChain9), m_pDeviceEx(pDevice), WrapperID(DeviceID), ProxyAddressLookupTable(pDevice->ProxyAddressLookupTable) { - LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ")"); + LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ") " << WrapperID); if (WrapperID == IID_IDirect3DSwapChain9Ex) {