From 4c03190ce80457f19f87f9a3a6b4b03fb4f08ee1 Mon Sep 17 00:00:00 2001 From: paramat Date: Sat, 22 Apr 2017 05:16:50 +0100 Subject: [PATCH] Mgflat, Mgv7: Fix noise crash on world exit. 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 | 4 +++- src/mapgen_v7.cpp | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/mapgen_flat.cpp b/src/mapgen_flat.cpp index c51b5e12e..0a44f71a5 100644 --- a/src/mapgen_flat.cpp +++ b/src/mapgen_flat.cpp @@ -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; } diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index c4583578f..420d77185 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -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; } -- 2.25.1