Skip to content

Commit

Permalink
Check index buffer size before creation
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Oct 11, 2024
1 parent 0fc7091 commit 670f86a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 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 7236
#define BUILD_NUMBER 7237
20 changes: 13 additions & 7 deletions ddraw/IDirect3DDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3665,13 +3665,6 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE dptPrimitive
return DDERR_GENERIC;
}

LPDIRECT3DINDEXBUFFER9 d3d9IndexBuffer = pVertexBufferX->SetupIndexBuffer(lpwIndices, dwIndexCount);
if (!d3d9IndexBuffer)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: could not get d3d9 index buffer!");
return DDERR_GENERIC;
}

DWORD FVF = pVertexBufferX->GetFVF9();

// Set fixed function vertex type
Expand All @@ -3681,6 +3674,19 @@ HRESULT m_IDirect3DDeviceX::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE dptPrimitive
return DDERR_INVALIDPARAMS;
}

// No operation to performed
if (dwIndexCount == 0)
{
return D3D_OK;
}

LPDIRECT3DINDEXBUFFER9 d3d9IndexBuffer = pVertexBufferX->SetupIndexBuffer(lpwIndices, dwIndexCount);
if (!d3d9IndexBuffer)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: could not get d3d9 index buffer!");
return DDERR_GENERIC;
}

// Set stream source
(*d3d9Device)->SetStreamSource(0, d3d9VertexBuffer, 0, GetVertexStride(FVF));

Expand Down
3 changes: 2 additions & 1 deletion ddraw/IDirect3DVertexBufferX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ LPDIRECT3DINDEXBUFFER9 m_IDirect3DVertexBufferX::SetupIndexBuffer(LPWORD lpwIndi

if (FAILED(hr))
{
LOG_LIMIT(100, __FUNCTION__ << " Error: failed to create index buffer: " << (D3DERR)hr);
LOG_LIMIT(100, __FUNCTION__ << " Error: failed to create index buffer: " << (D3DERR)hr << " Size: " << NewIndexSize);
return nullptr;
}

Expand Down Expand Up @@ -726,6 +726,7 @@ void m_IDirect3DVertexBufferX::ReleaseD3D9IndexBuffer()
Logging::Log() << __FUNCTION__ << " (" << this << ")" << " Error: there is still a reference to 'd3d9IndexBuffer' " << ref;
}
d3d9IndexBuffer = nullptr;
IndexBufferSize = 0;
}
}

Expand Down
6 changes: 4 additions & 2 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "d3dx9.h"
#include "Utils\Utils.h"

constexpr DWORD ExtraDataBufferSize = 200;

// Used to allow presenting non-primary surfaces in case the primary surface present fails
bool dirtyFlag = false;
bool SceneReady = false;
Expand Down Expand Up @@ -4840,7 +4842,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateDCSurface()
ZeroMemory(surface.emu->bmiMemory, sizeof(surface.emu->bmiMemory));
surface.emu->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
surface.emu->bmi->bmiHeader.biWidth = Width;
surface.emu->bmi->bmiHeader.biHeight = -((LONG)Height + 200);
surface.emu->bmi->bmiHeader.biHeight = -((LONG)Height + ExtraDataBufferSize);
surface.emu->bmi->bmiHeader.biPlanes = 1;
surface.emu->bmi->bmiHeader.biBitCount = (WORD)surface.BitCount;
surface.emu->bmi->bmiHeader.biCompression =
Expand Down Expand Up @@ -5492,7 +5494,7 @@ void m_IDirectDrawSurfaceX::LockEmuLock(LPRECT lpDestRect, LPDDSURFACEDESC2 lpDD
EmuLock.Height = lpDDSurfaceDesc->dwHeight;

// Update surface memory and pitch
size_t Size = NewPitch * lpDDSurfaceDesc->dwHeight;
size_t Size = NewPitch * (lpDDSurfaceDesc->dwHeight + ExtraDataBufferSize);
if (EmuLock.Mem.size() < Size)
{
EmuLock.Mem.resize(Size);
Expand Down

0 comments on commit 670f86a

Please sign in to comment.