From 2c23e462b377b110faf5bffed75035ac8f4cb176 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Sat, 31 Aug 2024 21:10:01 +0300 Subject: [PATCH] [d3d8] Clamp BaseVertexIndex to INT_MAX during use --- src/d3d8/d3d8_device.cpp | 7 +++++-- src/d3d8/d3d8_device.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/d3d8/d3d8_device.cpp b/src/d3d8/d3d8_device.cpp index 86ca46bbf..ec224298d 100644 --- a/src/d3d8/d3d8_device.cpp +++ b/src/d3d8/d3d8_device.cpp @@ -1168,7 +1168,7 @@ namespace dxvk { UINT PrimitiveCount) { return GetD3D9()->DrawIndexedPrimitive( d3d9::D3DPRIMITIVETYPE(PrimitiveType), - m_baseVertexIndex, // set by SetIndices + static_cast(std::min(m_baseVertexIndex, static_cast(INT_MAX))), // set by SetIndices MinVertexIndex, NumVertices, StartIndex, @@ -1292,8 +1292,11 @@ namespace dxvk { if (unlikely(ShouldRecord())) return m_recorder->SetIndices(pIndexData, BaseVertexIndex); + if (unlikely(BaseVertexIndex > INT_MAX)) + Logger::warn("BaseVertexIndex exceeds INT_MAX and will be clamped on use."); + // used by DrawIndexedPrimitive - m_baseVertexIndex = static_cast(BaseVertexIndex); + m_baseVertexIndex = BaseVertexIndex; D3D8IndexBuffer* buffer = static_cast(pIndexData); diff --git a/src/d3d8/d3d8_device.h b/src/d3d8/d3d8_device.h index eb46b8dfc..437989728 100644 --- a/src/d3d8/d3d8_device.h +++ b/src/d3d8/d3d8_device.h @@ -432,7 +432,7 @@ namespace dxvk { std::array m_streams; Com m_indices; - INT m_baseVertexIndex = 0; + UINT m_baseVertexIndex = 0; // TODO: Which of these should be a private ref std::vector> m_backBuffers;