From a6469fec4b91fa34880519509c544f213e40b550 Mon Sep 17 00:00:00 2001 From: titiger Date: Sun, 19 Feb 2017 20:45:30 +0100 Subject: [PATCH] Fix for Randomize Heights in Map Editor #147 --- source/shared_lib/sources/map/map_preview.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index 76540927d..cb0cbd87f 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -726,17 +726,16 @@ void MapPreview::randomizeFactions() { } void MapPreview::smoothSurface(bool limitHeight) { - float *oldHeights = new float[w*h]; - - for (int i = 0; i < w; ++i) { - for (int j = 0; j < h; ++j) { - oldHeights[i*w+j] = cells[i][j].height; - //printf("count=%d height=%f h=%f\n",i*w+h,oldHeights[i*w+h],cells[i][j].height); + float oldHeights [w*h]; + for (int j = 0; j < h; ++j) { + for (int i = 0; i < w; ++i) { + oldHeights[w*j+i] = cells[i][j].height; + //printf("w=%d h=%d i=%d j=%d w*h=%d w*j+i=%d \n",w,h,i,j,w*h,w*j+i); } } - for (int i = 1; i < w - 1; ++i) { - for (int j = 1; j < h - 1; ++j) { + for (int j = 1; j < h - 1; ++j) { + for (int i = 1; i < w - 1; ++i) { float height = 0.f; float numUsedToSmooth = 0.f; for (int k = -1; k <= 1; ++k) { @@ -756,7 +755,6 @@ void MapPreview::smoothSurface(bool limitHeight) { cells[i][j].height=height; } } - delete[] oldHeights; } void MapPreview::switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2) {