Skip to content

Commit

Permalink
Fix error in FindDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 2, 2024
1 parent c686217 commit 845f697
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7343
#define BUILD_NUMBER 7344
27 changes: 20 additions & 7 deletions ddraw/IDirect3DX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ HRESULT m_IDirect3DX::FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICE
case 7:
case 9:
{
if (!lpD3DFDS || !lpD3DFDR)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: invalid parameters!");
return DDERR_INVALIDPARAMS;
}

struct EnumFindDevice
{
bool Found = false;
Expand Down Expand Up @@ -587,16 +593,23 @@ HRESULT m_IDirect3DX::FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICE

if (CallbackContext.Found)
{
lpD3DFDR->guid = CallbackContext.DeviceDesc7.deviceGUID;
if (lpD3DFDR->ddHwDesc.dwSize)
DWORD Size = (lpD3DFDR->dwSize - sizeof(DWORD) - sizeof(GUID)) / 2;
if (Size != D3DDEVICEDESC1_SIZE && Size != D3DDEVICEDESC5_SIZE && Size != D3DDEVICEDESC6_SIZE)
{
ConvertDeviceDesc(lpD3DFDR->ddHwDesc, CallbackContext.DeviceDesc7);
}
if (lpD3DFDR->ddSwDesc.dwSize)
{
ConvertDeviceDesc(lpD3DFDR->ddSwDesc, CallbackContext.DeviceDesc7);
LOG_LIMIT(100, __FUNCTION__ << " Error: Incorrect dwSize: " << Size);
return DDERR_INVALIDPARAMS;
}

lpD3DFDR->guid = CallbackContext.DeviceDesc7.deviceGUID;

LPD3DDEVICEDESC lpddHwDesc = &lpD3DFDR->ddHwDesc;
lpddHwDesc->dwSize = Size;
ConvertDeviceDesc(*lpddHwDesc, CallbackContext.DeviceDesc7);

LPD3DDEVICEDESC lpddSwDesc = (LPD3DDEVICEDESC)((DWORD)lpddHwDesc + Size);
lpddSwDesc->dwSize = Size;
ConvertDeviceDesc(*lpddSwDesc, CallbackContext.DeviceDesc7);

return D3D_OK;
}

Expand Down

0 comments on commit 845f697

Please sign in to comment.