mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-05 07:08:46 +00:00
Fix crash in CogDebugDrawImGui
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "imgui_internal.h"
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
float FCogDebugDrawImGui::Time = 0;
|
||||||
TArray<FCogDebugDrawImGui::FLine> FCogDebugDrawImGui::Lines;
|
TArray<FCogDebugDrawImGui::FLine> FCogDebugDrawImGui::Lines;
|
||||||
TArray<FCogDebugDrawImGui::FTriangle> FCogDebugDrawImGui::Triangles;
|
TArray<FCogDebugDrawImGui::FTriangle> FCogDebugDrawImGui::Triangles;
|
||||||
TArray<FCogDebugDrawImGui::FTriangle> FCogDebugDrawImGui::TrianglesFilled;
|
TArray<FCogDebugDrawImGui::FTriangle> FCogDebugDrawImGui::TrianglesFilled;
|
||||||
@@ -22,7 +23,7 @@ void FCogDebugDrawImGui::AddLine(const ImVec2& P1, const ImVec2& P2, ImU32 Color
|
|||||||
Line.P2 = P2;
|
Line.P2 = P2;
|
||||||
Line.Color = Color;
|
Line.Color = Color;
|
||||||
Line.Thickness = Thickness;
|
Line.Thickness = Thickness;
|
||||||
Line.Time = ImGui::GetCurrentContext()->Time;
|
Line.Time = Time;
|
||||||
Line.Duration = Duration;
|
Line.Duration = Duration;
|
||||||
Line.FadeColor = FadeColor;
|
Line.FadeColor = FadeColor;
|
||||||
Lines.Add_GetRef(Line);
|
Lines.Add_GetRef(Line);
|
||||||
@@ -37,7 +38,7 @@ void FCogDebugDrawImGui::AddRect(const ImVec2& Min, const ImVec2& Max, ImU32 Col
|
|||||||
Rectangle.Color = Color;
|
Rectangle.Color = Color;
|
||||||
Rectangle.Rounding = Rounding;
|
Rectangle.Rounding = Rounding;
|
||||||
Rectangle.Thickness = Thickness;
|
Rectangle.Thickness = Thickness;
|
||||||
Rectangle.Time = ImGui::GetCurrentContext()->Time;
|
Rectangle.Time = Time;
|
||||||
Rectangle.Duration = Duration;
|
Rectangle.Duration = Duration;
|
||||||
Rectangle.FadeColor = FadeColor;
|
Rectangle.FadeColor = FadeColor;
|
||||||
Rectangles.Add_GetRef(Rectangle);
|
Rectangles.Add_GetRef(Rectangle);
|
||||||
@@ -52,7 +53,7 @@ void FCogDebugDrawImGui::AddRectFilled(const ImVec2& Min, const ImVec2& Max, ImU
|
|||||||
Rectangle.Color = Color;
|
Rectangle.Color = Color;
|
||||||
Rectangle.Rounding = Rounding;
|
Rectangle.Rounding = Rounding;
|
||||||
Rectangle.Thickness = 0.0f;
|
Rectangle.Thickness = 0.0f;
|
||||||
Rectangle.Time = ImGui::GetCurrentContext()->Time;
|
Rectangle.Time = Time;
|
||||||
Rectangle.Duration = Duration;
|
Rectangle.Duration = Duration;
|
||||||
Rectangle.FadeColor = FadeColor;
|
Rectangle.FadeColor = FadeColor;
|
||||||
RectanglesFilled.Add_GetRef(Rectangle);
|
RectanglesFilled.Add_GetRef(Rectangle);
|
||||||
@@ -68,7 +69,7 @@ void FCogDebugDrawImGui::AddQuad(const ImVec2& P1, const ImVec2& P2, const ImVec
|
|||||||
Quad.P4 = P4;
|
Quad.P4 = P4;
|
||||||
Quad.Color = Color;
|
Quad.Color = Color;
|
||||||
Quad.Thickness = Thickness;
|
Quad.Thickness = Thickness;
|
||||||
Quad.Time = ImGui::GetCurrentContext()->Time;
|
Quad.Time = Time;
|
||||||
Quad.Duration = Duration;
|
Quad.Duration = Duration;
|
||||||
Quad.FadeColor = FadeColor;
|
Quad.FadeColor = FadeColor;
|
||||||
Quads.Add_GetRef(Quad);
|
Quads.Add_GetRef(Quad);
|
||||||
@@ -84,7 +85,7 @@ void FCogDebugDrawImGui::AddQuadFilled(const ImVec2& P1, const ImVec2& P2, const
|
|||||||
Quad.P4 = P4;
|
Quad.P4 = P4;
|
||||||
Quad.Color = Color;
|
Quad.Color = Color;
|
||||||
Quad.Thickness = 0.0f;
|
Quad.Thickness = 0.0f;
|
||||||
Quad.Time = ImGui::GetCurrentContext()->Time;
|
Quad.Time = Time;
|
||||||
Quad.Duration = Duration;
|
Quad.Duration = Duration;
|
||||||
Quad.FadeColor = FadeColor;
|
Quad.FadeColor = FadeColor;
|
||||||
QuadsFilled.Add_GetRef(Quad);
|
QuadsFilled.Add_GetRef(Quad);
|
||||||
@@ -99,7 +100,7 @@ void FCogDebugDrawImGui::AddTriangle(const ImVec2& P1, const ImVec2& P2, const I
|
|||||||
Triangle.P3 = P3;
|
Triangle.P3 = P3;
|
||||||
Triangle.Color = Color;
|
Triangle.Color = Color;
|
||||||
Triangle.Thickness = Thickness;
|
Triangle.Thickness = Thickness;
|
||||||
Triangle.Time = ImGui::GetCurrentContext()->Time;
|
Triangle.Time = Time;
|
||||||
Triangle.Duration = Duration;
|
Triangle.Duration = Duration;
|
||||||
Triangle.FadeColor = FadeColor;
|
Triangle.FadeColor = FadeColor;
|
||||||
Triangles.Add_GetRef(Triangle);
|
Triangles.Add_GetRef(Triangle);
|
||||||
@@ -114,7 +115,7 @@ void FCogDebugDrawImGui::AddTriangleFilled(const ImVec2& P1, const ImVec2& P2, c
|
|||||||
Triangle.P3 = P3;
|
Triangle.P3 = P3;
|
||||||
Triangle.Color = Color;
|
Triangle.Color = Color;
|
||||||
Triangle.Thickness = 0.0f;
|
Triangle.Thickness = 0.0f;
|
||||||
Triangle.Time = ImGui::GetCurrentContext()->Time;
|
Triangle.Time = Time;
|
||||||
Triangle.Duration = Duration;
|
Triangle.Duration = Duration;
|
||||||
Triangle.FadeColor = FadeColor;
|
Triangle.FadeColor = FadeColor;
|
||||||
TrianglesFilled.Add_GetRef(Triangle);
|
TrianglesFilled.Add_GetRef(Triangle);
|
||||||
@@ -123,13 +124,14 @@ void FCogDebugDrawImGui::AddTriangleFilled(const ImVec2& P1, const ImVec2& P2, c
|
|||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void FCogDebugDrawImGui::AddCircle(const ImVec2& Center, float Radius, ImU32 Color, int Segments /*= 0*/, float Thickness /*= 1.0f*/, float Duration /*= 0.0f*/, bool FadeColor /*= false*/)
|
void FCogDebugDrawImGui::AddCircle(const ImVec2& Center, float Radius, ImU32 Color, int Segments /*= 0*/, float Thickness /*= 1.0f*/, float Duration /*= 0.0f*/, bool FadeColor /*= false*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
FCircle Circle;
|
FCircle Circle;
|
||||||
Circle.Center = Center;
|
Circle.Center = Center;
|
||||||
Circle.Radius = Radius > 0.0f ? Radius : 1.0f;
|
Circle.Radius = Radius > 0.0f ? Radius : 1.0f;
|
||||||
Circle.Color = Color;
|
Circle.Color = Color;
|
||||||
Circle.Segments = Segments;
|
Circle.Segments = Segments;
|
||||||
Circle.Thickness = Thickness;
|
Circle.Thickness = Thickness;
|
||||||
Circle.Time = ImGui::GetCurrentContext()->Time;
|
Circle.Time = Time;
|
||||||
Circle.Duration = Duration;
|
Circle.Duration = Duration;
|
||||||
Circle.FadeColor = FadeColor;
|
Circle.FadeColor = FadeColor;
|
||||||
Circles.Add_GetRef(Circle);
|
Circles.Add_GetRef(Circle);
|
||||||
@@ -144,7 +146,7 @@ void FCogDebugDrawImGui::AddCircleFilled(const ImVec2& Center, float Radius, ImU
|
|||||||
Circle.Color = Color;
|
Circle.Color = Color;
|
||||||
Circle.Segments = Segments;
|
Circle.Segments = Segments;
|
||||||
Circle.Thickness = 0.0f;
|
Circle.Thickness = 0.0f;
|
||||||
Circle.Time = ImGui::GetCurrentContext()->Time;
|
Circle.Time = Time;
|
||||||
Circle.Duration = Duration;
|
Circle.Duration = Duration;
|
||||||
Circle.FadeColor = FadeColor;
|
Circle.FadeColor = FadeColor;
|
||||||
CirclesFilled.Add_GetRef(Circle);
|
CirclesFilled.Add_GetRef(Circle);
|
||||||
@@ -157,7 +159,7 @@ void FCogDebugDrawImGui::AddText(const ImVec2& Pos, const FString& Text, ImU32 C
|
|||||||
TextElement.Pos = Pos;
|
TextElement.Pos = Pos;
|
||||||
TextElement.Text = Text;
|
TextElement.Text = Text;
|
||||||
TextElement.Color = Color;
|
TextElement.Color = Color;
|
||||||
TextElement.Time = ImGui::GetCurrentContext()->Time;
|
TextElement.Time = Time;
|
||||||
TextElement.Duration = Duration;
|
TextElement.Duration = Duration;
|
||||||
TextElement.FadeColor = FadeColor;
|
TextElement.FadeColor = FadeColor;
|
||||||
Texts.Add_GetRef(TextElement);
|
Texts.Add_GetRef(TextElement);
|
||||||
@@ -169,7 +171,7 @@ void FCogDebugDrawImGui::AddText(const ImVec2& Pos, const FString& Text, ImU32 C
|
|||||||
ShadowTextElement.Text = Text;
|
ShadowTextElement.Text = Text;
|
||||||
const float Alpha = ImGui::ColorConvertU32ToFloat4(Color).w; // Keep original Alpha and set to black
|
const float Alpha = ImGui::ColorConvertU32ToFloat4(Color).w; // Keep original Alpha and set to black
|
||||||
ShadowTextElement.Color = ImGui::ColorConvertFloat4ToU32(ImVec4(0, 0, 0, Alpha));
|
ShadowTextElement.Color = ImGui::ColorConvertFloat4ToU32(ImVec4(0, 0, 0, Alpha));
|
||||||
ShadowTextElement.Time = ImGui::GetCurrentContext()->Time;
|
ShadowTextElement.Time = Time;
|
||||||
ShadowTextElement.Duration = Duration;
|
ShadowTextElement.Duration = Duration;
|
||||||
ShadowTextElement.FadeColor = FadeColor;
|
ShadowTextElement.FadeColor = FadeColor;
|
||||||
Texts.Add_GetRef(ShadowTextElement);
|
Texts.Add_GetRef(ShadowTextElement);
|
||||||
@@ -181,6 +183,7 @@ void FCogDebugDrawImGui::AddText(const ImVec2& Pos, const FString& Text, ImU32 C
|
|||||||
void FCogDebugDrawImGui::Draw()
|
void FCogDebugDrawImGui::Draw()
|
||||||
{
|
{
|
||||||
ImDrawList* DrawList = ImGui::GetBackgroundDrawList();
|
ImDrawList* DrawList = ImGui::GetBackgroundDrawList();
|
||||||
|
Time = ImGui::GetCurrentContext()->Time;
|
||||||
|
|
||||||
DrawShapes(Lines, [DrawList](const FLine& Line, const ImColor Color) { DrawList->AddLine(Line.P1, Line.P2, Color, Line.Thickness); });
|
DrawShapes(Lines, [DrawList](const FLine& Line, const ImColor Color) { DrawList->AddLine(Line.P1, Line.P2, Color, Line.Thickness); });
|
||||||
DrawShapes(Rectangles, [DrawList](const FRectangle& Rectangle, const ImColor Color) { DrawList->AddRect(Rectangle.Min, Rectangle.Max, Color, Rectangle.Rounding, Rectangle.Thickness); });
|
DrawShapes(Rectangles, [DrawList](const FRectangle& Rectangle, const ImColor Color) { DrawList->AddRect(Rectangle.Min, Rectangle.Max, Color, Rectangle.Rounding, Rectangle.Thickness); });
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------------------
|
||||||
|
static float Time;
|
||||||
static TArray<FLine> Lines;
|
static TArray<FLine> Lines;
|
||||||
static TArray<FTriangle> Triangles;
|
static TArray<FTriangle> Triangles;
|
||||||
static TArray<FTriangle> TrianglesFilled;
|
static TArray<FTriangle> TrianglesFilled;
|
||||||
@@ -92,8 +93,6 @@ private:
|
|||||||
template<typename TShape, typename TDrawFunction>
|
template<typename TShape, typename TDrawFunction>
|
||||||
static void DrawShapes(TArray<TShape>& Shapes, TDrawFunction DrawFunction)
|
static void DrawShapes(TArray<TShape>& Shapes, TDrawFunction DrawFunction)
|
||||||
{
|
{
|
||||||
const double Time = ImGui::GetCurrentContext()->Time;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < Shapes.Num(); i++)
|
for (int32 i = 0; i < Shapes.Num(); i++)
|
||||||
{
|
{
|
||||||
const TShape& Shape = Shapes[i];
|
const TShape& Shape = Shapes[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user