Skip to content

Commit 3955f51

Browse files
committedFeb 16, 2017
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.
1 parent 2dcbc01 commit 3955f51

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed
 

‎src/mapblock.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,18 @@ typedef std::vector<MapBlock*> MapBlockVect;
669669

670670
inline bool objectpos_over_limit(v3f p)
671671
{
672-
const float map_gen_limit_bs = MYMIN(MAX_MAP_GENERATION_LIMIT,
673-
g_settings->getU16("map_generation_limit")) * BS;
674-
return (p.X < -map_gen_limit_bs
675-
|| p.X > map_gen_limit_bs
676-
|| p.Y < -map_gen_limit_bs
677-
|| p.Y > map_gen_limit_bs
678-
|| p.Z < -map_gen_limit_bs
679-
|| p.Z > map_gen_limit_bs);
672+
// MAP_BLOCKSIZE must be subtracted to avoid an object being spawned just
673+
// within the map generation limit but in a block and sector that extend
674+
// beyond the map generation limit.
675+
// This avoids crashes caused by sector over limit in createSector().
676+
const float object_limit = (MYMIN(MAX_MAP_GENERATION_LIMIT,
677+
g_settings->getU16("map_generation_limit")) - MAP_BLOCKSIZE) * BS;
678+
return (p.X < -object_limit
679+
|| p.X > object_limit
680+
|| p.Y < -object_limit
681+
|| p.Y > object_limit
682+
|| p.Z < -object_limit
683+
|| p.Z > object_limit);
680684
}
681685

682686
/*

‎src/serverenvironment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
16671667

16681668
if (objectpos_over_limit(object->getBasePosition())) {
16691669
v3f p = object->getBasePosition();
1670-
errorstream << "ServerEnvironment::addActiveObjectRaw(): "
1670+
warningstream << "ServerEnvironment::addActiveObjectRaw(): "
16711671
<< "object position (" << p.X << "," << p.Y << "," << p.Z
16721672
<< ") outside maximum range" << std::endl;
16731673
if (object->environmentDeletes())

0 commit comments

Comments
 (0)
Please sign in to comment.