From d511153836ae2b17044edf8ea457aacbbc52d3f9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 5 Oct 2015 01:54:19 +0200 Subject: [PATCH] Common: Fix element count computation if addr is null (RSXVertexData) --- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 757add8e20..934b109264 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -20,11 +20,15 @@ std::vector FormatVertexData(const RSXVertexData *m_vertex_d const RSXVertexData &vertexData = m_vertex_data[i]; if (!vertexData.IsEnabled()) continue; - size_t elementCount = vertex_data_size[i] / (vertexData.size * vertexData.GetTypeSize()); + size_t elementCount = ((vertexData.addr) ? vertex_data_size[i] : m_vertex_data[i].data.size()) / (vertexData.size * vertexData.GetTypeSize()); + // If there is a single element, stride is 0, use the size of element instead size_t stride = vertexData.stride; size_t elementSize = vertexData.GetTypeSize(); - std::pair range = std::make_pair(vertexData.addr + base_offset, vertexData.addr + base_offset + elementSize * vertexData.size + (elementCount - 1) * stride - 1); + size_t start = vertexData.addr + base_offset; + size_t end = start + elementSize * vertexData.size + (elementCount - 1) * stride - 1; + std::pair range = std::make_pair(start, end); + assert(start < end); bool isMerged = false; for (VertexBufferFormat &vbf : Result)