diff options
author | kwolekr <kwolekr@minetest.net> | 2014-11-29 16:50:18 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-11-29 16:52:45 -0500 |
commit | 25945dc5395a03cab069ff0e6470ba8d59b03978 (patch) | |
tree | 63b413140814c90197d55326e1d65b2672c978da /src/noise.cpp | |
parent | a3e019c4f6745d06d7afed7991b9c682b0ea65b9 (diff) | |
download | minetest-25945dc5395a03cab069ff0e6470ba8d59b03978.tar.gz minetest-25945dc5395a03cab069ff0e6470ba8d59b03978.tar.bz2 minetest-25945dc5395a03cab069ff0e6470ba8d59b03978.zip |
noise: Throw exception on noise allocation failure
Diffstat (limited to 'src/noise.cpp')
-rw-r--r-- | src/noise.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/noise.cpp b/src/noise.cpp index c0249a437..2d1b8d624 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -29,6 +29,7 @@ #include <string.h> // memset #include "debug.h" #include "util/numeric.h" +#include "exceptions.h" #define NOISE_MAGIC_X 1619 #define NOISE_MAGIC_Y 31337 @@ -336,8 +337,12 @@ Noise::Noise(NoiseParams *np, int seed, int sx, int sy, int sz) this->noisebuf = NULL; resizeNoiseBuf(sz > 1); - this->buf = new float[sx * sy * sz]; - this->result = new float[sx * sy * sz]; + try { + this->buf = new float[sx * sy * sz]; + this->result = new float[sx * sy * sz]; + } catch (std::bad_alloc &e) { + throw InvalidNoiseParamsException(); + } } @@ -360,8 +365,12 @@ void Noise::setSize(int sx, int sy, int sz) delete[] buf; delete[] result; - this->buf = new float[sx * sy * sz]; - this->result = new float[sx * sy * sz]; + try { + this->buf = new float[sx * sy * sz]; + this->result = new float[sx * sy * sz]; + } catch (std::bad_alloc &e) { + throw InvalidNoiseParamsException(); + } } @@ -399,7 +408,11 @@ void Noise::resizeNoiseBuf(bool is3d) if (noisebuf) delete[] noisebuf; - noisebuf = new float[nlx * nly * nlz]; + try { + noisebuf = new float[nlx * nly * nlz]; + } catch (std::bad_alloc &e) { + throw InvalidNoiseParamsException(); + } } @@ -615,7 +628,7 @@ float *Noise::perlinMap2DModulated(float x, float y, float *persist_map) f *= 2.0; } - + delete[] g; return result; } |