aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBřetislav Štec <valsiterb@gmail.com>2015-07-19 01:35:47 +0200
committerkwolekr <kwolekr@minetest.net>2015-07-27 11:06:46 -0400
commit88a6b9f52d6ffd4e351155dee661fe8ea084a9aa (patch)
tree8852b46e8337894bb26d034333878e737aea140f /src
parent9bc0241e44432491df9984be4f321e8bf94f2eb1 (diff)
downloadminetest-88a6b9f52d6ffd4e351155dee661fe8ea084a9aa.tar.gz
minetest-88a6b9f52d6ffd4e351155dee661fe8ea084a9aa.tar.bz2
minetest-88a6b9f52d6ffd4e351155dee661fe8ea084a9aa.zip
Fixed minimap memory leak
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp7
-rw-r--r--src/mapblock_mesh.cpp1
-rw-r--r--src/mapblock_mesh.h8
-rw-r--r--src/minimap.cpp8
4 files changed, 16 insertions, 8 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 63f720f04..fdabfa2d8 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -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)
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index 32f6e659a..33597b2fc 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -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)
diff --git a/src/mapblock_mesh.h b/src/mapblock_mesh.h
index 283006331..8e994ec6b 100644
--- a/src/mapblock_mesh.h
+++ b/src/mapblock_mesh.h
@@ -104,14 +104,16 @@ public:
// 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
diff --git a/src/minimap.cpp b/src/minimap.cpp
index d37a083ef..950202c6a 100644
--- a/src/minimap.cpp
+++ b/src/minimap.cpp
@@ -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);