mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Prevent invalid memory access under failure conditions
This commit is contained in:
parent
6ddf458504
commit
bc28ca0636
3 changed files with 64 additions and 61 deletions
|
@ -30,7 +30,8 @@ NoiseParams nparams_biome_def_heat(50, 50, v3f(500.0, 500.0, 500.0), 5349, 3, 0.
|
|||
NoiseParams nparams_biome_def_humidity(50, 50, v3f(500.0, 500.0, 500.0), 842, 3, 0.55);
|
||||
|
||||
|
||||
BiomeDefManager::BiomeDefManager(NodeResolver *resolver) {
|
||||
BiomeDefManager::BiomeDefManager(NodeResolver *resolver)
|
||||
{
|
||||
biome_registration_finished = false;
|
||||
np_heat = &nparams_biome_def_heat;
|
||||
np_humidity = &nparams_biome_def_humidity;
|
||||
|
@ -58,7 +59,8 @@ BiomeDefManager::BiomeDefManager(NodeResolver *resolver) {
|
|||
}
|
||||
|
||||
|
||||
BiomeDefManager::~BiomeDefManager() {
|
||||
BiomeDefManager::~BiomeDefManager()
|
||||
{
|
||||
//if (biomecache)
|
||||
// delete[] biomecache;
|
||||
|
||||
|
@ -67,7 +69,8 @@ BiomeDefManager::~BiomeDefManager() {
|
|||
}
|
||||
|
||||
|
||||
Biome *BiomeDefManager::createBiome(BiomeTerrainType btt) {
|
||||
Biome *BiomeDefManager::createBiome(BiomeTerrainType btt)
|
||||
{
|
||||
/*switch (btt) {
|
||||
case BIOME_TERRAIN_NORMAL:
|
||||
return new Biome;
|
||||
|
@ -86,7 +89,8 @@ Biome *BiomeDefManager::createBiome(BiomeTerrainType btt) {
|
|||
|
||||
|
||||
// just a PoC, obviously needs optimization later on (precalculate this)
|
||||
void BiomeDefManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map) {
|
||||
void BiomeDefManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map)
|
||||
{
|
||||
int i = 0;
|
||||
for (int y = 0; y != input->mapsize.Y; y++) {
|
||||
for (int x = 0; x != input->mapsize.X; x++, i++) {
|
||||
|
@ -98,29 +102,31 @@ void BiomeDefManager::calcBiomes(BiomeNoiseInput *input, u8 *biomeid_map) {
|
|||
}
|
||||
|
||||
|
||||
void BiomeDefManager::addBiome(Biome *b) {
|
||||
bool BiomeDefManager::addBiome(Biome *b)
|
||||
{
|
||||
if (biome_registration_finished) {
|
||||
errorstream << "BIomeDefManager: biome registration already "
|
||||
errorstream << "BiomeDefManager: biome registration already "
|
||||
"finished, dropping " << b->name << std::endl;
|
||||
delete b;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t nbiomes = biomes.size();
|
||||
if (nbiomes >= 0xFF) {
|
||||
errorstream << "BiomeDefManager: too many biomes, dropping "
|
||||
<< b->name << std::endl;
|
||||
delete b;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
b->id = (u8)nbiomes;
|
||||
biomes.push_back(b);
|
||||
verbosestream << "BiomeDefManager: added biome " << b->name << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Biome *BiomeDefManager::getBiome(float heat, float humidity, s16 y) {
|
||||
Biome *BiomeDefManager::getBiome(float heat, float humidity, s16 y)
|
||||
{
|
||||
Biome *b, *biome_closest = NULL;
|
||||
float dist_min = FLT_MAX;
|
||||
|
||||
|
@ -143,7 +149,8 @@ Biome *BiomeDefManager::getBiome(float heat, float humidity, s16 y) {
|
|||
}
|
||||
|
||||
|
||||
u8 BiomeDefManager::getBiomeIdByName(const char *name) {
|
||||
u8 BiomeDefManager::getBiomeIdByName(const char *name)
|
||||
{
|
||||
for (size_t i = 0; i != biomes.size(); i++) {
|
||||
if (!strcasecmp(name, biomes[i]->name.c_str()))
|
||||
return i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue