From e7307455f66c758e7db637a7b6adeea11160bae8 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 11 Mar 2015 08:04:19 +0000 Subject: [PATCH] Fix a crash if vertex input is instanced, with instance rate of 0 * In this case, every input takes the first index, need to avoid divide by 0 error. --- renderdocui/Windows/BufferViewer.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/renderdocui/Windows/BufferViewer.cs b/renderdocui/Windows/BufferViewer.cs index 6c2d5c282..7d9d4b120 100644 --- a/renderdocui/Windows/BufferViewer.cs +++ b/renderdocui/Windows/BufferViewer.cs @@ -1404,9 +1404,14 @@ namespace renderdocui.Windows Stream strm = state.m_Stream[bufferFormats[el].buffer]; BinaryReader read = state.m_Reader[bufferFormats[el].buffer]; - uint offs = input.Strides[bufferFormats[el].buffer] * - (bufferFormats[el].perinstance ? (instance/(uint)bufferFormats[el].instancerate) : index) - + bufferFormats[el].offset; + uint instIdx = 0; + // for instancing, need to handle instance rate being 0 (every instance takes index 0 in that case) + if (bufferFormats[el].perinstance) + instIdx = bufferFormats[el].instancerate > 0 ? (instance / (uint)bufferFormats[el].instancerate) : 0; + else + instIdx = index; + + uint offs = input.Strides[bufferFormats[el].buffer] * instIdx + bufferFormats[el].offset; if (!MeshView) offs += ByteOffset; @@ -1681,9 +1686,14 @@ namespace renderdocui.Windows Stream strm = state.m_Stream[bufferFormats[el].buffer]; BinaryReader read = state.m_Reader[bufferFormats[el].buffer]; - uint offs = input.Strides[bufferFormats[el].buffer] * - (bufferFormats[el].perinstance ? (instance / (uint)bufferFormats[el].instancerate) : dataIndex) - + bufferFormats[el].offset; + uint instIdx = 0; + // for instancing, need to handle instance rate being 0 (every instance takes index 0 in that case) + if (bufferFormats[el].perinstance) + instIdx = bufferFormats[el].instancerate > 0 ? (instance / (uint)bufferFormats[el].instancerate) : 0; + else + instIdx = dataIndex; + + uint offs = input.Strides[bufferFormats[el].buffer] * instIdx + bufferFormats[el].offset; if (!MeshView) offs += ByteOffset;