From ca7edc597c3df9cc481f7b30ac36174eb0cdb8b6 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Fri, 14 Jun 2024 11:32:20 +0300 Subject: [PATCH] Allocating indices on the stack --- openVulkanoCpp/Scene/GeometryFactory.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/openVulkanoCpp/Scene/GeometryFactory.cpp b/openVulkanoCpp/Scene/GeometryFactory.cpp index be01625..0dd3345 100644 --- a/openVulkanoCpp/Scene/GeometryFactory.cpp +++ b/openVulkanoCpp/Scene/GeometryFactory.cpp @@ -16,15 +16,18 @@ namespace OpenVulkano::Scene Geometry* GeometryFactory::MakeCube(float x, float y, float z, const Math::Vector4f& color) { Geometry *result = new Geometry(); - result->Init(24, 36); - result->SetIndices(new uint32_t[result->indexCount]{ - 0, 1, 2, 0, 2, 3, // front face index data - 4, 5, 6, 4, 6, 7, // back face index data - 8, 9, 10, 8, 10, 11, // top face index data - 12, 13, 14, 12, 14, 15, // bottom face index data - 16, 17, 18, 16, 18, 19, // left face index data - 20, 21, 22, 20, 22, 23 // right face index data - }, result->indexCount); + const int indexCount = 36; + result->Init(24, indexCount); + uint32_t indices[indexCount] = + { + 0, 1, 2, 0, 2, 3, // front face index data + 4, 5, 6, 4, 6, 7, // back face index data + 8, 9, 10, 8, 10, 11, // top face index data + 12, 13, 14, 12, 14, 15, // bottom face index data + 16, 17, 18, 16, 18, 19, // left face index data + 20, 21, 22, 20, 22, 23 // right face index data + }; + result->SetIndices(indices, result->indexCount); x *= 0.5f; y *= 0.5f; z *= 0.5f;