Mgflat, Mgv7: Fix noise crash on world exit.
authorparamat <mat.gregory@virginmedia.com>
Sat, 22 Apr 2017 04:16:50 +0000 (05:16 +0100)
committerparamat <mat.gregory@virginmedia.com>
Sat, 22 Apr 2017 04:37:33 +0000 (05:37 +0100)
Fix crash caused by destructor 'delete' on noise objects that are not
created due to mapgen options.
Crash was caused by commit 57eaf62c697cec91890d9cb28d10385d293d2d3f

src/mapgen_flat.cpp
src/mapgen_v7.cpp

index c51b5e12e65ccb0425003f3430af833b83317cd8..0a44f71a57d2e80618a6227fea1579c756fc2f55 100644 (file)
@@ -73,8 +73,10 @@ MapgenFlat::MapgenFlat(int mapgenid, MapgenFlatParams *params, EmergeManager *em
 
 MapgenFlat::~MapgenFlat()
 {
-       delete noise_terrain;
        delete noise_filler_depth;
+
+       if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
+               delete noise_terrain;
 }
 
 
index c4583578f412fd5c281218c50f782035b06ba0ad..420d771851a1a4559e7bae9d7cadf2257c2a7ec7 100644 (file)
@@ -97,16 +97,26 @@ MapgenV7::MapgenV7(int mapgenid, MapgenV7Params *params, EmergeManager *emerge)
 MapgenV7::~MapgenV7()
 {
        delete noise_terrain_base;
+       delete noise_terrain_alt;
        delete noise_terrain_persist;
        delete noise_height_select;
-       delete noise_terrain_alt;
        delete noise_filler_depth;
-       delete noise_mount_height;
-       delete noise_ridge_uwater;
-       delete noise_floatland_base;
-       delete noise_float_base_height;
-       delete noise_mountain;
-       delete noise_ridge;
+
+       if (spflags & MGV7_MOUNTAINS)
+               delete noise_mount_height;
+
+       if (spflags & MGV7_FLOATLANDS) {
+               delete noise_floatland_base;
+               delete noise_float_base_height;
+       }
+
+       if (spflags & MGV7_RIDGES) {
+               delete noise_ridge_uwater;
+               delete noise_ridge;
+       }
+
+       if ((spflags & MGV7_MOUNTAINS) || (spflags & MGV7_FLOATLANDS))
+               delete noise_mountain;
 }