From 7a2f98eea521d100048bc24cd65103a04fc1b084 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Thu, 17 Oct 2024 22:21:36 +0300 Subject: [PATCH] Add "D3DFMT_UNKNOWN" checks on object creation (#184) --- source/d3d8to9_device.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/d3d8to9_device.cpp b/source/d3d8to9_device.cpp index 75d712d..959e557 100644 --- a/source/d3d8to9_device.cpp +++ b/source/d3d8to9_device.cpp @@ -279,6 +279,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateTexture(UINT Width, UINT Height if (ppTexture == nullptr) return D3DERR_INVALIDCALL; + if (Format == D3DFMT_UNKNOWN) + return D3DERR_INVALIDCALL; + *ppTexture = nullptr; if (Pool == D3DPOOL_DEFAULT) @@ -312,6 +315,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVolumeTexture(UINT Width, UINT if (ppVolumeTexture == nullptr) return D3DERR_INVALIDCALL; + if (Format == D3DFMT_UNKNOWN) + return D3DERR_INVALIDCALL; + *ppVolumeTexture = nullptr; IDirect3DVolumeTexture9 *TextureInterface = nullptr; @@ -329,6 +335,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateCubeTexture(UINT EdgeLength, UI if (ppCubeTexture == nullptr) return D3DERR_INVALIDCALL; + if (Format == D3DFMT_UNKNOWN) + return D3DERR_INVALIDCALL; + *ppCubeTexture = nullptr; IDirect3DCubeTexture9 *TextureInterface = nullptr; @@ -380,6 +389,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateRenderTarget(UINT Width, UINT H if (ppSurface == nullptr) return D3DERR_INVALIDCALL; + if (Format == D3DFMT_UNKNOWN) + return D3DERR_INVALIDCALL; + *ppSurface = nullptr; DWORD QualityLevels = 0; @@ -409,6 +421,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateDepthStencilSurface(UINT Width, if (ppSurface == nullptr) return D3DERR_INVALIDCALL; + if (Format == D3DFMT_UNKNOWN) + return D3DERR_INVALIDCALL; + *ppSurface = nullptr; DWORD QualityLevels = 0; @@ -442,8 +457,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateImageSurface(UINT Width, UINT H if (ppSurface == nullptr) return D3DERR_INVALIDCALL; + // Only CreateImageSurface clears the content of ppSurface + // before checking if Format is equal to D3DFMT_UNKNOWN. *ppSurface = nullptr; + if (Format == D3DFMT_UNKNOWN) + return D3DERR_INVALIDCALL; + IDirect3DSurface9 *SurfaceInterface = nullptr; const HRESULT hr = ProxyInterface->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &SurfaceInterface, nullptr);