diff options
author | paramat <mat.gregory@virginmedia.com> | 2017-02-13 04:37:25 +0000 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-02-16 22:25:07 +0000 |
commit | 3955f512538ca7c6f2d2187f22d5a696da8e84d3 (patch) | |
tree | 6b5d81be8add98d55f33015cf8d151926f360add | |
parent | 2dcbc019044b1af22e056c5bdb586f94c83092ad (diff) | |
download | minetest-3955f512538ca7c6f2d2187f22d5a696da8e84d3.tar.gz minetest-3955f512538ca7c6f2d2187f22d5a696da8e84d3.tar.bz2 minetest-3955f512538ca7c6f2d2187f22d5a696da8e84d3.zip |
Objectpos over limit: Avoid crash caused by sector over limit
Reduce the object limit by mapblock size, to avoid objects being
added just inside the map generation limit but in a block and sector
that extend beyond the map generation limit.
Change notification of 'objectpos over limit' from red in-chat ERROR
to in-terminal only WARNING, since this will happen often using mob
mods near the world's edge.
-rw-r--r-- | src/mapblock.h | 20 | ||||
-rw-r--r-- | src/serverenvironment.cpp | 2 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/mapblock.h b/src/mapblock.h index 5a0ec937a..bec3b6f56 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -669,14 +669,18 @@ typedef std::vector<MapBlock*> MapBlockVect; inline bool objectpos_over_limit(v3f p) { - const float map_gen_limit_bs = MYMIN(MAX_MAP_GENERATION_LIMIT, - g_settings->getU16("map_generation_limit")) * BS; - return (p.X < -map_gen_limit_bs - || p.X > map_gen_limit_bs - || p.Y < -map_gen_limit_bs - || p.Y > map_gen_limit_bs - || p.Z < -map_gen_limit_bs - || p.Z > map_gen_limit_bs); + // MAP_BLOCKSIZE must be subtracted to avoid an object being spawned just + // within the map generation limit but in a block and sector that extend + // beyond the map generation limit. + // This avoids crashes caused by sector over limit in createSector(). + const float object_limit = (MYMIN(MAX_MAP_GENERATION_LIMIT, + g_settings->getU16("map_generation_limit")) - MAP_BLOCKSIZE) * BS; + return (p.X < -object_limit + || p.X > object_limit + || p.Y < -object_limit + || p.Y > object_limit + || p.Z < -object_limit + || p.Z > object_limit); } /* diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 61faaace7..f3f489092 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1667,7 +1667,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, if (objectpos_over_limit(object->getBasePosition())) { v3f p = object->getBasePosition(); - errorstream << "ServerEnvironment::addActiveObjectRaw(): " + warningstream << "ServerEnvironment::addActiveObjectRaw(): " << "object position (" << p.X << "," << p.Y << "," << p.Z << ") outside maximum range" << std::endl; if (object->environmentDeletes()) |