summaryrefslogtreecommitdiff
path: root/src/mapgen/cavegen.cpp
diff options
context:
space:
mode:
authorParamat <paramat@users.noreply.github.com>2018-06-26 19:35:23 +0100
committerGitHub <noreply@github.com>2018-06-26 19:35:23 +0100
commit93661ca2122639b000dc3860700e5c61ebbc6497 (patch)
treed64c257104325daa15c879a831fc216e40542693 /src/mapgen/cavegen.cpp
parentb589352e79de438590d94f98783dbf1601454d91 (diff)
downloadminetest-93661ca2122639b000dc3860700e5c61ebbc6497.tar.gz
minetest-93661ca2122639b000dc3860700e5c61ebbc6497.tar.bz2
minetest-93661ca2122639b000dc3860700e5c61ebbc6497.zip
Cavegen: Fix errors when getting biome outside mapchunk (#7480)
Some cave segments are outside the mapchunk. Previously, biome was being calculated by a function that uses the noise maps. Points outside the mapchunk resulted in incorrect noise map indexes that were sometimes outside the noise map size, causing a crash. Use either noise maps or point noise calculations depending on point location.
Diffstat (limited to 'src/mapgen/cavegen.cpp')
-rw-r--r--src/mapgen/cavegen.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp
index 363219f6d..e54d76e08 100644
--- a/src/mapgen/cavegen.cpp
+++ b/src/mapgen/cavegen.cpp
@@ -507,7 +507,16 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz)
MapNode liquidnode = CONTENT_IGNORE;
if (bmgn) {
- Biome *biome = (Biome *)bmgn->getBiomeAtPoint(cpabs);
+ Biome *biome = nullptr;
+ if (cpabs.X < node_min.X || cpabs.X > node_max.X ||
+ cpabs.Z < node_min.Z || cpabs.Z > node_max.Z)
+ // Point is outside heat and humidity noise maps so use point noise
+ // calculations.
+ biome = (Biome *)bmgn->calcBiomeAtPoint(cpabs);
+ else
+ // Point is inside heat and humidity noise maps so use them
+ biome = (Biome *)bmgn->getBiomeAtPoint(cpabs);
+
if (biome->c_cave_liquid != CONTENT_IGNORE)
liquidnode = biome->c_cave_liquid;
}