From 8a567f084950930dffde32fcb8de692471c4961c Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sat, 6 Feb 2021 11:29:48 +0100 Subject: [PATCH 1/4] Fix issue #214 --- Source/Engine/Debug/DebugDraw.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 457c90411..cdf1f412a 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -629,7 +629,11 @@ void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color& void DebugDraw::DrawLines(const Span& lines, const Matrix& transform, const Color& color, float duration, bool depthTest) { - ASSERT(lines.Length() % 2 == 0); + if (lines.Length() % 2 == 0) + { + LOG(Error, "Cannot draw debug lines with uneven amount of items in array"); + return; + } // Create draw call entry DebugLine l = { Vector3::Zero, Vector3::Zero, Color32(color), duration }; @@ -637,10 +641,12 @@ void DebugDraw::DrawLines(const Span& lines, const Matrix& transform, c // Add lines const Vector3* p = lines.Get(); Array* list; - if (depthTest) + + if (depthTest) list = duration > 0 ? &DebugDrawDepthTest.DefaultLines : &DebugDrawDepthTest.OneFrameLines; - else + else list = duration > 0 ? &DebugDrawDefault.DefaultLines : &DebugDrawDefault.OneFrameLines; + list->EnsureCapacity(list->Count() + lines.Length()); for (int32 i = 0; i < lines.Length(); i += 2) { From 5b3275653654120f294defeb20f995d7d303f73e Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sat, 6 Feb 2021 11:32:58 +0100 Subject: [PATCH 2/4] Remove empty space Just noticed it, so bye bye. --- Source/Engine/Debug/DebugDraw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index cdf1f412a..f8b4a35ef 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -644,7 +644,7 @@ void DebugDraw::DrawLines(const Span& lines, const Matrix& transform, c if (depthTest) list = duration > 0 ? &DebugDrawDepthTest.DefaultLines : &DebugDrawDepthTest.OneFrameLines; - else + else list = duration > 0 ? &DebugDrawDefault.DefaultLines : &DebugDrawDefault.OneFrameLines; list->EnsureCapacity(list->Count() + lines.Length()); From f5d1ad5a9b2737b6d7412e67c007a2d1d7146715 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sat, 6 Feb 2021 13:32:04 +0100 Subject: [PATCH 3/4] Use ThrowException instead --- Source/Engine/Debug/DebugDraw.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index f8b4a35ef..c197a0d0d 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -19,6 +19,7 @@ #include "Engine/Graphics/RenderBuffers.h" #include "Engine/Animations/AnimationUtils.h" #include "Engine/Profiler/Profiler.h" +#include "Engine/Debug/DebugLog.h" // Debug draw service configuration #define DEBUG_DRAW_INITIAL_VB_CAPACITY (4 * 1024) @@ -631,7 +632,7 @@ void DebugDraw::DrawLines(const Span& lines, const Matrix& transform, c { if (lines.Length() % 2 == 0) { - LOG(Error, "Cannot draw debug lines with uneven amount of items in array"); + DebugLog::ThrowException("Cannot draw debug lines with uneven amount of items in array"); return; } From 522e1eb76974e3d04d516a68db7ecad6b588dc8a Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sat, 6 Feb 2021 20:10:22 +0100 Subject: [PATCH 4/4] Inverted condition --- Source/Engine/Debug/DebugDraw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index c197a0d0d..f954cd7cb 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -630,7 +630,7 @@ void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color& void DebugDraw::DrawLines(const Span& lines, const Matrix& transform, const Color& color, float duration, bool depthTest) { - if (lines.Length() % 2 == 0) + if (lines.Length() % 2 != 0) { DebugLog::ThrowException("Cannot draw debug lines with uneven amount of items in array"); return;