From 2031e1a4c4663994add4806e58b8a28f2396c0c6 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sun, 1 Dec 2024 22:28:42 +0100 Subject: [PATCH] Fix memory leak on vertices allocations --- Engine/Graphics/3DRenderer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Engine/Graphics/3DRenderer.cpp b/Engine/Graphics/3DRenderer.cpp index 3b3c175..ae504d9 100644 --- a/Engine/Graphics/3DRenderer.cpp +++ b/Engine/Graphics/3DRenderer.cpp @@ -120,7 +120,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { { size_t vCount = obj->GetObjectVerticesCount(); auto& oMesh = obj->GetObjectMesh(); - M3D_F4* projVertices = new M3D_F4[vCount]; + auto* projVertices = new M3D_F4[vCount]; // Vertices homogeneous clip space transformation M3D_V3Transform( @@ -131,7 +131,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { ); // Draw the object indice triangles if visible or partially clipped - sf::Vertex v_tri[4]; + auto* v_tri = new sf::Vertex[4]; for (auto& objPt : oMesh.parts) { auto indicePtr = static_cast(objPt.indices.data()); @@ -189,7 +189,8 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { } } - std::destroy_at(projVertices); + delete[] v_tri; + delete[] projVertices; } } }