Try and be defensive about lack of index data

* ArgumentException thrown from BlockCopy seen in a crash upload, and
  it might be because of an empty or null buffer returned, maybe.
This commit is contained in:
baldurk
2015-02-12 21:36:46 +00:00
parent 3c6a1316d5
commit ce20926f20
+21 -14
View File
@@ -914,22 +914,29 @@ namespace renderdocui.Windows
input.IndexOffset + input.Drawcall.indexOffset * input.Drawcall.indexByteWidth,
ret.IndexCount * input.Drawcall.indexByteWidth);
ret.Indices = new uint[rawidxs.Length / input.Drawcall.indexByteWidth];
if (input.Drawcall.indexByteWidth == 2)
if (input.Drawcall.indexByteWidth == 0 || rawidxs == null || rawidxs.Length == 0)
{
ushort[] tmp = new ushort[rawidxs.Length / 2];
Buffer.BlockCopy(rawidxs, 0, tmp, 0, rawidxs.Length);
for (int i = 0; i < tmp.Length; i++)
{
ret.Indices[i] = tmp[i];
}
ret.Indices = new uint[0] { };
}
else if (input.Drawcall.indexByteWidth == 4)
else
{
Buffer.BlockCopy(rawidxs, 0, ret.Indices, 0, rawidxs.Length);
ret.Indices = new uint[rawidxs.Length / input.Drawcall.indexByteWidth];
if (input.Drawcall.indexByteWidth == 2)
{
ushort[] tmp = new ushort[rawidxs.Length / 2];
Buffer.BlockCopy(rawidxs, 0, tmp, 0, rawidxs.Length);
for (int i = 0; i < tmp.Length; i++)
{
ret.Indices[i] = tmp[i];
}
}
else if (input.Drawcall.indexByteWidth == 4)
{
Buffer.BlockCopy(rawidxs, 0, ret.Indices, 0, rawidxs.Length);
}
}
uint minIndex = ret.Indices.Length > 0 ? ret.Indices[0] : 0;
@@ -963,7 +970,7 @@ namespace renderdocui.Windows
input.IndexOffset + input.Drawcall.indexOffset * input.Drawcall.indexByteWidth,
ret.IndexCount * input.Drawcall.indexByteWidth);
if (input.Drawcall.indexByteWidth == 0)
if (input.Drawcall.indexByteWidth == 0 || rawidxs == null || rawidxs.Length == 0)
{
ret.Indices = new uint[0];
}