mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 17:40:39 +00:00
Fix some crashes and bad handling of indices
* If buffer wasn't a multiple of 4, a Buffer.BlockCopy call could crash * Unsigned byte indices (for GL) weren't supported * Post-transform index buffer was assumed to just be uints, but in fact it is the same size as the drawcall's existing indices.
This commit is contained in:
@@ -923,11 +923,16 @@ namespace renderdocui.Windows
|
||||
{
|
||||
ret.Indices = new uint[rawidxs.Length / input.Drawcall.indexByteWidth];
|
||||
|
||||
if (input.Drawcall.indexByteWidth == 2)
|
||||
if (input.Drawcall.indexByteWidth == 1)
|
||||
{
|
||||
for (int i = 0; i < rawidxs.Length; i++)
|
||||
ret.Indices[i] = rawidxs[i];
|
||||
}
|
||||
else if (input.Drawcall.indexByteWidth == 2)
|
||||
{
|
||||
ushort[] tmp = new ushort[rawidxs.Length / 2];
|
||||
|
||||
Buffer.BlockCopy(rawidxs, 0, tmp, 0, rawidxs.Length);
|
||||
Buffer.BlockCopy(rawidxs, 0, tmp, 0, tmp.Length * sizeof(ushort));
|
||||
|
||||
for (int i = 0; i < tmp.Length; i++)
|
||||
{
|
||||
@@ -936,7 +941,7 @@ namespace renderdocui.Windows
|
||||
}
|
||||
else if (input.Drawcall.indexByteWidth == 4)
|
||||
{
|
||||
Buffer.BlockCopy(rawidxs, 0, ret.Indices, 0, rawidxs.Length);
|
||||
Buffer.BlockCopy(rawidxs, 0, ret.Indices, 0, ret.Indices.Length * sizeof(uint));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -948,8 +953,28 @@ namespace renderdocui.Windows
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.DataIndices = new uint[rawidxs.Length / sizeof(uint)];
|
||||
Buffer.BlockCopy(rawidxs, 0, ret.DataIndices, 0, rawidxs.Length);
|
||||
ret.DataIndices = new uint[rawidxs.Length / input.Drawcall.indexByteWidth];
|
||||
|
||||
if (input.Drawcall.indexByteWidth == 1)
|
||||
{
|
||||
for (int i = 0; i < rawidxs.Length; i++)
|
||||
ret.DataIndices[i] = rawidxs[i];
|
||||
}
|
||||
else if (input.Drawcall.indexByteWidth == 2)
|
||||
{
|
||||
ushort[] tmp = new ushort[rawidxs.Length / 2];
|
||||
|
||||
Buffer.BlockCopy(rawidxs, 0, tmp, 0, tmp.Length * sizeof(ushort));
|
||||
|
||||
for (int i = 0; i < tmp.Length; i++)
|
||||
{
|
||||
ret.DataIndices[i] = tmp[i];
|
||||
}
|
||||
}
|
||||
else if (input.Drawcall.indexByteWidth == 4)
|
||||
{
|
||||
Buffer.BlockCopy(rawidxs, 0, ret.DataIndices, 0, ret.DataIndices.Length * sizeof(uint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -975,11 +1000,16 @@ namespace renderdocui.Windows
|
||||
{
|
||||
ret.Indices = new uint[rawidxs.Length / input.Drawcall.indexByteWidth];
|
||||
|
||||
if (input.Drawcall.indexByteWidth == 2)
|
||||
if (input.Drawcall.indexByteWidth == 1)
|
||||
{
|
||||
for (int i = 0; i < rawidxs.Length; i++)
|
||||
ret.Indices[i] = rawidxs[i];
|
||||
}
|
||||
else if (input.Drawcall.indexByteWidth == 2)
|
||||
{
|
||||
ushort[] tmp = new ushort[rawidxs.Length / 2];
|
||||
|
||||
Buffer.BlockCopy(rawidxs, 0, tmp, 0, rawidxs.Length);
|
||||
Buffer.BlockCopy(rawidxs, 0, tmp, 0, tmp.Length * sizeof(ushort));
|
||||
|
||||
for (int i = 0; i < tmp.Length; i++)
|
||||
{
|
||||
@@ -988,16 +1018,14 @@ namespace renderdocui.Windows
|
||||
}
|
||||
else if (input.Drawcall.indexByteWidth == 4)
|
||||
{
|
||||
Buffer.BlockCopy(rawidxs, 0, ret.Indices, 0, rawidxs.Length);
|
||||
Buffer.BlockCopy(rawidxs, 0, ret.Indices, 0, ret.Indices.Length * sizeof(uint));
|
||||
}
|
||||
}
|
||||
|
||||
maxIndex = 0;
|
||||
foreach (var i in ret.Indices)
|
||||
{
|
||||
if (input.Drawcall.indexByteWidth == 2 && i == input.IndexRestartValue && input.IndexRestart)
|
||||
continue;
|
||||
if (input.Drawcall.indexByteWidth == 4 && i == input.IndexRestartValue && input.IndexRestart)
|
||||
if (i == input.IndexRestartValue && input.IndexRestart)
|
||||
continue;
|
||||
|
||||
maxIndex = Math.Max(maxIndex, i);
|
||||
|
||||
Reference in New Issue
Block a user