Fix DebugDraw DrawTriangles crash

This commit is contained in:
Wojtek Figat
2021-02-10 17:20:05 +01:00
parent 29521b1b03
commit 6c253ce892
2 changed files with 33 additions and 4 deletions

View File

@@ -869,9 +869,9 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Color& color,
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
else
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
list->EnsureCapacity(list->Count() + vertices.Length());
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
for (int32 i = 0; i < vertices.Length() * 3;)
for (int32 i = 0; i < vertices.Length();)
{
t.V0 = vertices[i++];
t.V1 = vertices[i++];
@@ -881,6 +881,11 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Color& color,
}
}
void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Color& color, float duration, bool depthTest)
{
DrawTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration, bool depthTest)
{
ASSERT(indices.Length() % 3 == 0);
@@ -894,9 +899,9 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>&
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
else
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
list->EnsureCapacity(list->Count() + indices.Length());
list->EnsureCapacity(list->Count() + indices.Length() / 3);
for (int32 i = 0; i < indices.Length() * 3;)
for (int32 i = 0; i < indices.Length();)
{
t.V0 = vertices[indices[i++]];
t.V1 = vertices[indices[i++]];
@@ -906,6 +911,11 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>&
}
}
void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Array<int32, HeapAllocation>& indices, const Color& color, float duration, bool depthTest)
{
DrawTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), Span<int32>(indices.Get(), indices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawWireTube(const Vector3& position, const Quaternion& orientation, float radius, float length, const Color& color, float duration, bool depthTest)
{
// Check if has no length (just sphere)

View File

@@ -113,6 +113,15 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
API_FUNCTION() static void DrawTriangles(const Span<Vector3>& vertices, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the triangles.
/// </summary>
/// <param name="vertices">The triangle vertices list (must have multiple of 3 elements).</param>
/// <param name="color">The color.</param>
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
static void DrawTriangles(const Array<Vector3, HeapAllocation>& vertices, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the triangles using the given index buffer.
/// </summary>
@@ -123,6 +132,16 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
API_FUNCTION() static void DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the triangles using the given index buffer.
/// </summary>
/// <param name="vertices">The triangle vertices list.</param>
/// <param name="indices">The triangle indices list (must have multiple of 3 elements).</param>
/// <param name="color">The color.</param>
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
static void DrawTriangles(const Array<Vector3, HeapAllocation>& vertices, const Array<int32, HeapAllocation>& indices, const Color& color, float duration = 0.0f, bool depthTest = true);
/// <summary>
/// Draws the wireframe box.
/// </summary>