From dee559bd16e5fc4fb1d8cdd16e7e3924666b01c9 Mon Sep 17 00:00:00 2001 From: Loki Rautio Date: Thu, 26 Mar 2026 01:37:23 -0500 Subject: Revert "Memory leak fix: Make chunks unload properly (#1406)" This reverts commit a24318eedc44af2f5967c4727b7ebf578b8e233a. This fix introduces broken behavior for dedicated servers. It will be merged back in once the related issue is fixed --- Minecraft.Client/ServerChunkCache.cpp | 57 +++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'Minecraft.Client/ServerChunkCache.cpp') diff --git a/Minecraft.Client/ServerChunkCache.cpp b/Minecraft.Client/ServerChunkCache.cpp index 54312ffa..c7d70c7d 100644 --- a/Minecraft.Client/ServerChunkCache.cpp +++ b/Minecraft.Client/ServerChunkCache.cpp @@ -80,31 +80,54 @@ vector *ServerChunkCache::getLoadedChunkList() return &m_loadedChunkList; } -void ServerChunkCache::drop(const int x, const int z) +void ServerChunkCache::drop(int x, int z) { - const int ix = x + XZOFFSET; - const int iz = z + XZOFFSET; - if ((ix < 0) || (ix >= XZSIZE)) return; - if ((iz < 0) || (iz >= XZSIZE)) return; - const int idx = ix * XZSIZE + iz; - LevelChunk* chunk = cache[idx]; - - if (chunk != nullptr) - { - const auto it = std::find(m_loadedChunkList.begin(), m_loadedChunkList.end(), chunk); - if (it != m_loadedChunkList.end()) m_loadedChunkList.erase(it); + // 4J - we're not dropping things anymore now that we have a fixed sized cache +#ifdef _LARGE_WORLDS - cache[idx] = nullptr; - chunk->loaded = false; + bool canDrop = false; +// if (level->dimension->mayRespawn()) +// { +// Pos *spawnPos = level->getSharedSpawnPos(); +// int xd = x * 16 + 8 - spawnPos->x; +// int zd = z * 16 + 8 - spawnPos->z; +// delete spawnPos; +// int r = 128; +// if (xd < -r || xd > r || zd < -r || zd > r) +// { +// canDrop = true; +//} +// } +// else + { + canDrop = true; + } + if(canDrop) + { + int ix = x + XZOFFSET; + int iz = z + XZOFFSET; + // Check we're in range of the stored level + if( ( ix < 0 ) || ( ix >= XZSIZE ) ) return; + if( ( iz < 0 ) || ( iz >= XZSIZE ) ) return; + int idx = ix * XZSIZE + iz; + LevelChunk *chunk = cache[idx]; + + if(chunk) + { + m_toDrop.push_back(chunk); + } } +#endif } void ServerChunkCache::dropAll() { +#ifdef _LARGE_WORLDS for (LevelChunk *chunk : m_loadedChunkList) { drop(chunk->x, chunk->z); - } +} +#endif } // 4J - this is the original (and virtual) interface to create @@ -934,10 +957,6 @@ bool ServerChunkCache::tick() m_unloadedCache[idx] = chunk; cache[idx] = nullptr; } - else - { - continue; - } } m_toDrop.pop_front(); } -- cgit v1.2.3