mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-03-26 23:02:00 +02:00
Revert "Memory leak fix: Make chunks unload properly (#1406)"
This reverts commit a24318eedc.
This fix introduces broken behavior for dedicated servers. It will be
merged back in once the related issue is fixed
This commit is contained in:
@@ -80,31 +80,54 @@ vector<LevelChunk *> *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];
|
||||
// 4J - we're not dropping things anymore now that we have a fixed sized cache
|
||||
#ifdef _LARGE_WORLDS
|
||||
|
||||
if (chunk != nullptr)
|
||||
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
|
||||
{
|
||||
const auto it = std::find(m_loadedChunkList.begin(), m_loadedChunkList.end(), chunk);
|
||||
if (it != m_loadedChunkList.end()) m_loadedChunkList.erase(it);
|
||||
|
||||
cache[idx] = nullptr;
|
||||
chunk->loaded = false;
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user