From 0baa2eb64918681ad8681902b427c6ad8ace8350 Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Wed, 22 Feb 2023 21:54:15 +0100 Subject: [PATCH] memory: use proper delete[] --- include/intervalmap.hpp | 2 ++ src/chunkmesher.cpp | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/intervalmap.hpp b/include/intervalmap.hpp index 56b1802..5f6151e 100644 --- a/include/intervalmap.hpp +++ b/include/intervalmap.hpp @@ -75,6 +75,8 @@ public: const auto &end = std::prev(treemap.end()); *length = end->first; + if(*length == 0) return nullptr; + // std::cout << "Length: " << *length << "\n"; V *arr{new V[*length]}; diff --git a/src/chunkmesher.cpp b/src/chunkmesher.cpp index e49b4cb..087a8e3 100755 --- a/src/chunkmesher.cpp +++ b/src/chunkmesher.cpp @@ -41,12 +41,13 @@ void mesh(Chunk::Chunk* chunk) indices.clear(); vIndex = 0; - if(chunk->getState(Chunk::CHUNK_STATE_EMPTY)) return; + // if(chunk->getState(Chunk::CHUNK_STATE_EMPTY)) return; // convert tree to array since it is easier to work with it int length{0}; Block *blocks = chunk->getBlocksArray(&length); - + if(length == 0) return; + int k, l, u, v, w, h, n, j, i; int x[]{0, 0, 0}; int q[]{0, 0, 0}; @@ -182,9 +183,6 @@ void mesh(Chunk::Chunk* chunk) } } - if (blocks) - delete blocks; - if (vIndex > 0) { @@ -216,6 +214,7 @@ void mesh(Chunk::Chunk* chunk) indices.clear(); colors.clear(); } + delete[] blocks; }