Guard BindBuffer/BufferData calls for empty arrays

- Issue MatterHackers/MCCentral#3843
Crash when model is floating above plate with no supports
This commit is contained in:
John Lewin 2018-07-12 12:07:33 -07:00
parent 79804f354b
commit 18fd48d562

View file

@ -49,23 +49,29 @@ namespace MatterHackers.GCodeVisualizer
// Set vertex data
myVertexLength = colorData.Length;
GL.BindBuffer(BufferTarget.ArrayBuffer, myVertexId);
unsafe
if (myVertexLength > 0)
{
fixed (ColorVertexData* dataPointer = colorData)
GL.BindBuffer(BufferTarget.ArrayBuffer, myVertexId);
unsafe
{
GL.BufferData(BufferTarget.ArrayBuffer, colorData.Length * ColorVertexData.Stride, (IntPtr)dataPointer, BufferUsageHint.StaticDraw);
fixed (ColorVertexData* dataPointer = colorData)
{
GL.BufferData(BufferTarget.ArrayBuffer, colorData.Length * ColorVertexData.Stride, (IntPtr)dataPointer, BufferUsageHint.StaticDraw);
}
}
}
// Set index data
myIndexLength = indexData.Length;
GL.BindBuffer(BufferTarget.ElementArrayBuffer, myIndexId);
unsafe
if (myIndexLength > 0)
{
fixed (int* dataPointer = indexData)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, myIndexId);
unsafe
{
GL.BufferData(BufferTarget.ElementArrayBuffer, indexData.Length * sizeof(int), (IntPtr)dataPointer, BufferUsageHint.StaticDraw);
fixed (int* dataPointer = indexData)
{
GL.BufferData(BufferTarget.ElementArrayBuffer, indexData.Length * sizeof(int), (IntPtr)dataPointer, BufferUsageHint.StaticDraw);
}
}
}
}