From e234d8b3786d5adfbdf3d1a2123c3e8d91c21880 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Wed, 8 Jul 2015 00:45:24 -0400 Subject: Clean-up Minimap code - Fixed race conditions - Fixed null dereference - Fixed out-of-bounds array access - MinimapMapblock is now allocated and added to update queue only when enabled - Removed dependency on LocalPlayer - Fixed code style - Simplified expressions and program logic - Cleaned minimap object interfaces --- src/client.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index 2f8babfa2..66aac6229 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -525,18 +525,23 @@ void Client::step(float dtime) while (!m_mesh_update_thread.m_queue_out.empty()) { num_processed_meshes++; + + MinimapMapblock *minimap_mapblock = NULL; + bool do_mapper_update = true; + MeshUpdateResult r = m_mesh_update_thread.m_queue_out.pop_frontNoEx(); MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(r.p); - MinimapMapblock *minimap_mapblock = NULL; if (block) { // Delete the old mesh - if (block->mesh != NULL) { + if (block->mesh != NULL) { delete block->mesh; block->mesh = NULL; } - if (r.mesh) + if (r.mesh) { minimap_mapblock = r.mesh->getMinimapMapblock(); + do_mapper_update = (minimap_mapblock != NULL); + } if (r.mesh && r.mesh->getMesh()->getMeshBufferCount() == 0) { delete r.mesh; @@ -550,7 +555,8 @@ void Client::step(float dtime) minimap_mapblock = NULL; } - m_mapper->addBlock(r.p, minimap_mapblock); + if (do_mapper_update) + m_mapper->addBlock(r.p, minimap_mapblock); if (r.ack_block_to_server) { /* -- cgit v1.2.3