From 7bc5d16f72dae6e9efcc9bf6ec7762054ddbfc29 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <Joseph.WaltonRivers@falmouth.ac.uk> Date: Tue, 19 Apr 2022 16:13:17 +0100 Subject: [PATCH] make windows happy by avoiding storing the heightmap on the stack --- fggl/data/heightmap.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fggl/data/heightmap.cpp b/fggl/data/heightmap.cpp index c2a915d..0c7dcf6 100644 --- a/fggl/data/heightmap.cpp +++ b/fggl/data/heightmap.cpp @@ -15,7 +15,7 @@ namespace fggl::data { const int gridOffset = sizeX * sizeY; // calculate normals for each triangle - math::vec3 triNormals[sizeX * sizeY * 2]; + math::vec3* triNormals = new math::vec3[sizeX * sizeY * 2]; for (int i = 0; i < sizeX - 1; i++) { for (int j = 0; j < sizeY - 1; j++) { // calculate vertex @@ -66,12 +66,15 @@ namespace fggl::data { locations[idx(i, j, sizeY)].normal = glm::normalize(finalNormal) * -1.0f; //FIXME the normals seem wrong. } } + delete[] triNormals; } void generateHeightMesh(const data::HeightMap *heights, data::Mesh &mesh) { // step 1: convert height data into vertex locations - data::Vertex locations[data::heightMaxZ * data::heightMaxZ]; + const int numElms = data::heightMaxX * data::heightMaxZ; + data::Vertex* locations = new data::Vertex[numElms]; + for (std::size_t x = 0; x < data::heightMaxX; x++) { for (std::size_t z = 0; z < data::heightMaxZ; z++) { float level = heights->getValue(x, z); @@ -88,9 +91,10 @@ namespace fggl::data { mesh.restartVertex = data::heightMaxZ * data::heightMaxX; // populate mesh - for (auto & location : locations) { - mesh.pushVertex(location); + for (auto i = 0; i < numElms; i++) { + mesh.pushVertex(locations[i]); } + delete[] locations; for (std::size_t x = 0; x < data::heightMaxX - 1; x++) { for (std::size_t z = 0; z < data::heightMaxZ; z++) { -- GitLab