From 3d1be5dfede6db975d599ce4f3951d74c33faf4c Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Mon, 10 Feb 2025 15:42:41 +0200 Subject: [PATCH] Using unique ptr for indices --- openVulkanoCpp/Scene/Export/MeshWriter.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/openVulkanoCpp/Scene/Export/MeshWriter.cpp b/openVulkanoCpp/Scene/Export/MeshWriter.cpp index cc74c18..17054ce 100644 --- a/openVulkanoCpp/Scene/Export/MeshWriter.cpp +++ b/openVulkanoCpp/Scene/Export/MeshWriter.cpp @@ -27,8 +27,8 @@ namespace { #if __has_include("assimp/Exporter.hpp") - void SetupAssimpScene(OpenVulkano::Scene::Geometry* geometry, aiScene& scene, aiNode& rootNode, aiMesh& mesh, unsigned int*& indices, - bool withTexCoords, float scaling) + void SetupAssimpScene(OpenVulkano::Scene::Geometry* geometry, aiScene& scene, aiNode& rootNode, aiMesh& mesh, + std::unique_ptr& indices, bool withTexCoords, float scaling) { mesh.mVertices = nullptr; mesh.mNormals = nullptr; @@ -75,7 +75,7 @@ namespace mesh.mNumFaces = geometry->indexCount / 3; mesh.mFaces = new aiFace[mesh.mNumFaces]; - indices = new unsigned int[geometry->indexCount]; + indices = std::make_unique(geometry->indexCount); for (unsigned int i = 0; i < geometry->indexCount; ++i) { @@ -172,7 +172,7 @@ namespace OpenVulkano::Scene std::unique_ptr scene(new aiScene()); std::unique_ptr rootNode(new aiNode()); std::unique_ptr mesh(new aiMesh()); - unsigned int* indices = nullptr; + std::unique_ptr indices; SetupAssimpScene(geometry, *scene, *rootNode, *mesh, indices, false, 1.0f); @@ -187,7 +187,6 @@ namespace OpenVulkano::Scene aiFace& face = mesh->mFaces[i]; face.mIndices = nullptr; } - delete[] indices; if (result != aiReturn_SUCCESS) { @@ -204,7 +203,7 @@ namespace OpenVulkano::Scene std::unique_ptr scene(new aiScene()); std::unique_ptr rootNode(new aiNode()); std::unique_ptr mesh(new aiMesh()); - unsigned int* indices = nullptr; + std::unique_ptr indices; SetupAssimpScene(geometry, *scene, *rootNode, *mesh, indices, true, 100.0f); @@ -224,7 +223,6 @@ namespace OpenVulkano::Scene aiFace& face = mesh->mFaces[i]; face.mIndices = nullptr; } - delete[] indices; if (result != aiReturn_SUCCESS) {