From 175c2b00a8835bdbc992061280f8408b4e2bc63a Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Sun, 9 Feb 2025 19:19:36 -0800 Subject: [PATCH] Fix some interface reference issues --- Dllmain/BuildNo.rc | 2 +- ddraw/IDirect3DX.cpp | 6 ++++-- ddraw/IDirectDrawSurfaceX.cpp | 8 ++++++++ ddraw/IDirectDrawSurfaceX.h | 5 +++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index 9c69c1c8..20ba3a68 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7506 +#define BUILD_NUMBER 7507 diff --git a/ddraw/IDirect3DX.cpp b/ddraw/IDirect3DX.cpp index f545fd4a..217ca3c6 100644 --- a/ddraw/IDirect3DX.cpp +++ b/ddraw/IDirect3DX.cpp @@ -993,7 +993,8 @@ void m_IDirect3DX::ReleaseInterface() // Release Viewport for (auto& entry : ViewportList) { - if (entry->Release()) + m_IDirect3DViewport* Viewport = (m_IDirect3DViewport*)entry->GetWrapperInterfaceX(0); + if (!Viewport || Viewport->Release()) { entry->ClearD3D(); } @@ -1002,7 +1003,8 @@ void m_IDirect3DX::ReleaseInterface() // Release Material for (auto& entry : MaterialList) { - if (entry->Release()) + m_IDirect3DMaterial* Material = (m_IDirect3DMaterial*)entry->GetWrapperInterfaceX(0); + if (!Material || Material->Release()) { entry->ClearD3D(); } diff --git a/ddraw/IDirectDrawSurfaceX.cpp b/ddraw/IDirectDrawSurfaceX.cpp index 60a211d3..7de1e55f 100644 --- a/ddraw/IDirectDrawSurfaceX.cpp +++ b/ddraw/IDirectDrawSurfaceX.cpp @@ -160,6 +160,8 @@ HRESULT m_IDirectDrawSurfaceX::QueryInterface(REFIID riid, LPVOID FAR* ppvObj, D { InterfaceX = new m_IDirect3DTextureX(ddrawParent->GetCurrentD3DDevice(), DxVersion, this); attached3DTexture = InterfaceX; + attached3dTextureRefversion = DirectXVersion; + AddRef(attached3dTextureRefversion); } *ppvObj = InterfaceX->GetWrapperInterfaceX(DxVersion); @@ -4165,6 +4167,12 @@ void m_IDirectDrawSurfaceX::InitInterface(DWORD DirectXVersion) InitSurfaceDesc(DirectXVersion); } +void m_IDirectDrawSurfaceX::ClearAttachedTexture() +{ + attached3DTexture = nullptr; + Release(attached3dTextureRefversion); +} + void m_IDirectDrawSurfaceX::SetDdrawParent(m_IDirectDrawX* ddraw) { ddrawParent = ddraw; diff --git a/ddraw/IDirectDrawSurfaceX.h b/ddraw/IDirectDrawSurfaceX.h index 91f4d0d3..b46ca91c 100644 --- a/ddraw/IDirectDrawSurfaceX.h +++ b/ddraw/IDirectDrawSurfaceX.h @@ -165,7 +165,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj CRITICAL_SECTION ddscs = {}; CRITICAL_SECTION ddlcs = {}; m_IDirectDrawX *ddrawParent = nullptr; // DirectDraw parent device - SURFACEOVERLAY SurfaceOverlay; // The overlays for this surface + SURFACEOVERLAY SurfaceOverlay; // The overlays for this surface std::vector MipMaps; // MipMaps structure with addresses DWORD MaxMipMapLevel = 0; // Total number of manually created MipMap levels bool IsMipMapReadyToUse = false; // Used for MipMap filtering @@ -174,6 +174,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj m_IDirectDrawPalette *attachedPalette = nullptr; // Associated palette m_IDirectDrawClipper *attachedClipper = nullptr; // Associated clipper m_IDirect3DTextureX *attached3DTexture = nullptr; // Associated texture + DWORD attached3dTextureRefversion = 0; // Reference wrapper version for associated texture DDSURFACEDESC2 surfaceDesc2 = {}; // Surface description for this surface DWORD ResetDisplayFlags = 0; // Flags that need to be reset when display mode changes DWORD UniquenessValue = 0; @@ -521,7 +522,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj inline D3DFORMAT GetD3d9Format() const { return surface.Format; } inline LPDIRECT3DTEXTURE9 GetD3d9PaletteTexture() const { return primary.PaletteTexture; } inline m_IDirect3DTextureX* GetAttachedTexture() { return attached3DTexture; } - inline void ClearAttachedTexture() { attached3DTexture = nullptr; } + void ClearAttachedTexture(); void ClearUsing3DFlag(); HRESULT GetPresentWindowRect(LPRECT pRect, RECT& DestRect);