summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParamat <paramat@users.noreply.github.com>2020-02-12 23:15:07 +0000
committerGitHub <noreply@github.com>2020-02-12 23:15:07 +0000
commitc2f48eab4dfd352c391266b858378dd032d84a0f (patch)
tree9e55e1920b9788128ad34b35075e78c881f568e2
parent2d5e0ce5babb0b4fbc16783fdea013528161ab62 (diff)
downloadminetest-c2f48eab4dfd352c391266b858378dd032d84a0f.tar.gz
minetest-c2f48eab4dfd352c391266b858378dd032d84a0f.tar.bz2
minetest-c2f48eab4dfd352c391266b858378dd032d84a0f.zip
Display an error when a noise parameter has too many octaves (#9394)
Display an error and throw exception when one or more octaves of a noise has spread < 1, causing random looking broken noise.
-rw-r--r--src/noise.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/noise.cpp b/src/noise.cpp
index 255d3faee..9c91a6df4 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -503,23 +503,32 @@ void Noise::setOctaves(int octaves)
void Noise::resizeNoiseBuf(bool is3d)
{
- //maximum possible spread value factor
+ // Maximum possible spread value factor
float ofactor = (np.lacunarity > 1.0) ?
pow(np.lacunarity, np.octaves - 1) :
np.lacunarity;
- // noise lattice point count
+ // Noise lattice point count
// (int)(sz * spread * ofactor) is # of lattice points crossed due to length
float num_noise_points_x = sx * ofactor / np.spread.X;
float num_noise_points_y = sy * ofactor / np.spread.Y;
float num_noise_points_z = sz * ofactor / np.spread.Z;
- // protect against obviously invalid parameters
+ // Protect against obviously invalid parameters
if (num_noise_points_x > 1000000000.f ||
- num_noise_points_y > 1000000000.f ||
- num_noise_points_z > 1000000000.f)
+ num_noise_points_y > 1000000000.f ||
+ num_noise_points_z > 1000000000.f)
throw InvalidNoiseParamsException();
+ // Protect against an octave having a spread < 1, causing broken noise values
+ if (np.spread.X / ofactor < 1.0f ||
+ np.spread.Y / ofactor < 1.0f ||
+ np.spread.Z / ofactor < 1.0f) {
+ errorstream << "A noise parameter has too many octaves: "
+ << np.octaves << " octaves" << std::endl;
+ throw InvalidNoiseParamsException("A noise parameter has too many octaves");
+ }
+
// + 2 for the two initial endpoints
// + 1 for potentially crossing a boundary due to offset
size_t nlx = (size_t)std::ceil(num_noise_points_x) + 3;