Skip to content

Commit

Permalink
Fixed minimap memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
t0suj4 authored and kwolekr committed Jul 27, 2015
1 parent 9bc0241 commit 88a6b9f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/client.cpp
Expand Up @@ -540,20 +540,19 @@ void Client::step(float dtime)
}

if (r.mesh) {
minimap_mapblock = r.mesh->getMinimapMapblock();
do_mapper_update = (minimap_mapblock != NULL);
minimap_mapblock = r.mesh->moveMinimapMapblock();
if (minimap_mapblock == NULL)
do_mapper_update = false;
}

if (r.mesh && r.mesh->getMesh()->getMeshBufferCount() == 0) {
delete r.mesh;
block->mesh = NULL;
} else {
// Replace with the new mesh
block->mesh = r.mesh;
}
} else {
delete r.mesh;
minimap_mapblock = NULL;
}

if (do_mapper_update)
Expand Down
1 change: 1 addition & 0 deletions src/mapblock_mesh.cpp
Expand Up @@ -1278,6 +1278,7 @@ MapBlockMesh::~MapBlockMesh()
{
m_mesh->drop();
m_mesh = NULL;
delete m_minimap_mapblock;
}

bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
Expand Down
8 changes: 5 additions & 3 deletions src/mapblock_mesh.h
Expand Up @@ -104,14 +104,16 @@ class MapBlockMesh
// Returns true if anything has been changed.
bool animate(bool faraway, float time, int crack, u32 daynight_ratio);

scene::SMesh* getMesh()
scene::SMesh *getMesh()
{
return m_mesh;
}

MinimapMapblock* getMinimapMapblock()
MinimapMapblock *moveMinimapMapblock()
{
return m_minimap_mapblock;
MinimapMapblock *p = m_minimap_mapblock;
m_minimap_mapblock = NULL;
return p;
}

bool isAnimationForced() const
Expand Down
8 changes: 7 additions & 1 deletion src/minimap.cpp
Expand Up @@ -102,7 +102,13 @@ void MinimapUpdateThread::doUpdate()

while (popBlockUpdate(&update)) {
if (update.data) {
m_blocks_cache[update.pos] = update.data;
// Swap two values in the map using single lookup
std::pair<std::map<v3s16, MinimapMapblock*>::iterator, bool>
result = m_blocks_cache.insert(std::make_pair(update.pos, update.data));
if (result.second == false) {
delete result.first->second;
result.first->second = update.data;
}
} else {
std::map<v3s16, MinimapMapblock *>::iterator it;
it = m_blocks_cache.find(update.pos);
Expand Down

0 comments on commit 88a6b9f

Please sign in to comment.