aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PlayerChunkMap.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-25 00:25:18 -0400
committerGitHub <noreply@github.com>2026-03-24 23:25:18 -0500
commita24318eedc44af2f5967c4727b7ebf578b8e233a (patch)
tree90edf89155728ed68f2192109b7b542ef526f26e /Minecraft.Client/PlayerChunkMap.cpp
parent993052409a2ff6c997aea77f8f8fe143d08f5993 (diff)
Memory leak fix: Make chunks unload properly (#1406)main
* Fix chunk unload and cleanup logic, fixes #1347 * Applying formatting to code I edited 😝
Diffstat (limited to 'Minecraft.Client/PlayerChunkMap.cpp')
-rw-r--r--Minecraft.Client/PlayerChunkMap.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Minecraft.Client/PlayerChunkMap.cpp b/Minecraft.Client/PlayerChunkMap.cpp
index bcc3f6ba..ddf2bae2 100644
--- a/Minecraft.Client/PlayerChunkMap.cpp
+++ b/Minecraft.Client/PlayerChunkMap.cpp
@@ -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;