noise: Throw exception on noise allocation failure
parent
a3e019c4f6
commit
25945dc539
|
@ -125,6 +125,18 @@ public:
|
||||||
Some "old-style" interrupts:
|
Some "old-style" interrupts:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class InvalidNoiseParamsException : public BaseException {
|
||||||
|
public:
|
||||||
|
InvalidNoiseParamsException():
|
||||||
|
BaseException("One or more noise parameters were invalid or require "
|
||||||
|
"too much memory")
|
||||||
|
{}
|
||||||
|
|
||||||
|
InvalidNoiseParamsException(const std::string &s):
|
||||||
|
BaseException(s)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
class InvalidPositionException : public BaseException
|
class InvalidPositionException : public BaseException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <string.h> // memset
|
#include <string.h> // memset
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "util/numeric.h"
|
#include "util/numeric.h"
|
||||||
|
#include "exceptions.h"
|
||||||
|
|
||||||
#define NOISE_MAGIC_X 1619
|
#define NOISE_MAGIC_X 1619
|
||||||
#define NOISE_MAGIC_Y 31337
|
#define NOISE_MAGIC_Y 31337
|
||||||
|
@ -336,8 +337,12 @@ Noise::Noise(NoiseParams *np, int seed, int sx, int sy, int sz)
|
||||||
this->noisebuf = NULL;
|
this->noisebuf = NULL;
|
||||||
resizeNoiseBuf(sz > 1);
|
resizeNoiseBuf(sz > 1);
|
||||||
|
|
||||||
|
try {
|
||||||
this->buf = new float[sx * sy * sz];
|
this->buf = new float[sx * sy * sz];
|
||||||
this->result = 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[] buf;
|
||||||
delete[] result;
|
delete[] result;
|
||||||
|
try {
|
||||||
this->buf = new float[sx * sy * sz];
|
this->buf = new float[sx * sy * sz];
|
||||||
this->result = 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)
|
if (noisebuf)
|
||||||
delete[] noisebuf;
|
delete[] noisebuf;
|
||||||
|
try {
|
||||||
noisebuf = new float[nlx * nly * nlz];
|
noisebuf = new float[nlx * nly * nlz];
|
||||||
|
} catch (std::bad_alloc &e) {
|
||||||
|
throw InvalidNoiseParamsException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,11 @@ int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size) {
|
LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size) {
|
||||||
|
try {
|
||||||
noise = new Noise(np, seed, size.X, size.Y, size.Z);
|
noise = new Noise(np, seed, size.X, size.Y, size.Z);
|
||||||
|
} catch (InvalidNoiseParamsException &e) {
|
||||||
|
throw LuaError(e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaPerlinNoiseMap::~LuaPerlinNoiseMap()
|
LuaPerlinNoiseMap::~LuaPerlinNoiseMap()
|
||||||
|
|
Loading…
Reference in New Issue