mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
LuaPerlinNoiseMap: Prevent invalid memory access when attempting to generate 3d noise with a buffer created for 2d
This commit is contained in:
parent
00fc0babe0
commit
4e5d17f666
@ -60,17 +60,6 @@ LuaPerlinNoise::LuaPerlinNoise(NoiseParams *params) :
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
LuaPerlinNoise::LuaPerlinNoise(int a_seed, int a_octaves,
|
||||
float a_persistence, float a_scale)
|
||||
{
|
||||
np.seed = a_seed;
|
||||
np.octaves = a_octaves;
|
||||
np.persist = a_persistence;
|
||||
np.spread = v3f(a_scale, a_scale, a_scale);
|
||||
}
|
||||
*/
|
||||
|
||||
LuaPerlinNoise::~LuaPerlinNoise()
|
||||
{
|
||||
}
|
||||
@ -215,6 +204,9 @@ int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
|
||||
LuaPerlinNoiseMap *o = checkobject(L, 1);
|
||||
v3f p = read_v3f(L, 2);
|
||||
|
||||
if (!o->m_is3d)
|
||||
return 0;
|
||||
|
||||
Noise *n = o->noise;
|
||||
n->perlinMap3D(p.X, p.Y, p.Z);
|
||||
|
||||
@ -242,6 +234,9 @@ int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
|
||||
LuaPerlinNoiseMap *o = checkobject(L, 1);
|
||||
v3f p = read_v3f(L, 2);
|
||||
|
||||
if (!o->m_is3d)
|
||||
return 0;
|
||||
|
||||
Noise *n = o->noise;
|
||||
n->perlinMap3D(p.X, p.Y, p.Z);
|
||||
|
||||
@ -256,11 +251,12 @@ int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
|
||||
}
|
||||
|
||||
|
||||
LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *np, int seed, v3s16 size)
|
||||
LuaPerlinNoiseMap::LuaPerlinNoiseMap(NoiseParams *params, int seed, v3s16 size)
|
||||
{
|
||||
memcpy(&m_noise_params, np, sizeof(m_noise_params));
|
||||
m_is3d = size.Z <= 1;
|
||||
np = *params;
|
||||
try {
|
||||
noise = new Noise(&m_noise_params, 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());
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
class LuaPerlinNoise : public ModApiBase {
|
||||
private:
|
||||
NoiseParams np;
|
||||
|
||||
static const char className[];
|
||||
static const luaL_reg methods[];
|
||||
|
||||
@ -59,8 +58,9 @@ public:
|
||||
LuaPerlinNoiseMap
|
||||
*/
|
||||
class LuaPerlinNoiseMap : public ModApiBase {
|
||||
NoiseParams m_noise_params;
|
||||
NoiseParams np;
|
||||
Noise *noise;
|
||||
bool m_is3d;
|
||||
static const char className[];
|
||||
static const luaL_reg methods[];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user