mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-03-26 01:08:11 +05:00
Memory leak fix: Make chunks unload properly (#1406)
* Fix chunk unload and cleanup logic, fixes #1347 * Applying formatting to code I edited 😝
This commit is contained in:
@@ -792,6 +792,14 @@ void PlayerChunkMap::setRadius(int newRadius)
|
||||
int xc = static_cast<int>(player->x) >> 4;
|
||||
int zc = static_cast<int>(player->z) >> 4;
|
||||
|
||||
for (auto it = addRequests.begin(); it != addRequests.end(); )
|
||||
{
|
||||
if (it->player == player)
|
||||
it = addRequests.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
for (int x = xc - newRadius; x <= xc + newRadius; x++)
|
||||
for (int z = zc - newRadius; z <= zc + newRadius; z++)
|
||||
{
|
||||
@@ -801,9 +809,26 @@ void PlayerChunkMap::setRadius(int newRadius)
|
||||
getChunkAndAddPlayer(x, z, player);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove chunks that are outside the new radius
|
||||
for (int x = xc - radius; x <= xc + radius; x++)
|
||||
{
|
||||
for (int z = zc - radius; z <= zc + radius; z++)
|
||||
{
|
||||
if (x < xc - newRadius || x > xc + newRadius || z < zc - newRadius || z > zc + newRadius)
|
||||
{
|
||||
getChunkAndRemovePlayer(x, z, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newRadius < radius)
|
||||
{
|
||||
level->cache->dropAll();
|
||||
}
|
||||
|
||||
assert(radius <= MAX_VIEW_DISTANCE);
|
||||
assert(radius >= MIN_VIEW_DISTANCE);
|
||||
this->radius = newRadius;
|
||||
|
||||
Reference in New Issue
Block a user