From 9749d9fee6db99da1ab861dc04ec63ef973db3e0 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 5 Mar 2015 15:34:39 +0100 Subject: [PATCH] Fix issue #2441: crash on respawn, since a conversion std::list to std::vector on Environment.cpp * Also change some std::list to std::vector for ClientMap::renderMap * Remove disabled code in ClientMap::renderMap, disabled since a long time --- src/clientmap.cpp | 85 +++++++-------------------------- src/environment.cpp | 11 +++-- src/mapgen.cpp | 5 +- src/mapgen.h | 2 +- src/nodedef.cpp | 12 ++--- src/nodedef.h | 2 +- src/script/lua_api/l_mapgen.cpp | 2 +- 7 files changed, 35 insertions(+), 84 deletions(-) diff --git a/src/clientmap.cpp b/src/clientmap.cpp index b9516fcbe..1c420b5f9 100644 --- a/src/clientmap.cpp +++ b/src/clientmap.cpp @@ -391,12 +391,12 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) struct MeshBufList { video::SMaterial m; - std::list bufs; + std::vector bufs; }; struct MeshBufListList { - std::list lists; + std::vector lists; void clear() { @@ -405,7 +405,7 @@ struct MeshBufListList void add(scene::IMeshBuffer *buf) { - for(std::list::iterator i = lists.begin(); + for(std::vector::iterator i = lists.begin(); i != lists.end(); ++i){ MeshBufList &l = *i; video::SMaterial &m = buf->getMaterial(); @@ -595,25 +595,20 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } } - std::list &lists = drawbufs.lists; + std::vector &lists = drawbufs.lists; int timecheck_counter = 0; - for(std::list::iterator i = lists.begin(); - i != lists.end(); ++i) - { - { - timecheck_counter++; - if(timecheck_counter > 50) - { - timecheck_counter = 0; - int time2 = time(0); - if(time2 > time1 + 4) - { - infostream<<"ClientMap::renderMap(): " - "Rendering takes ages, returning." - <::iterator i = lists.begin(); + i != lists.end(); ++i) { + timecheck_counter++; + if(timecheck_counter > 50) { + timecheck_counter = 0; + int time2 = time(0); + if(time2 > time1 + 4) { + infostream << "ClientMap::renderMap(): " + "Rendering takes ages, returning." + << std::endl; + return; } } @@ -621,60 +616,14 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) driver->setMaterial(list.m); - for(std::list::iterator j = list.bufs.begin(); - j != list.bufs.end(); ++j) - { + for(std::vector::iterator j = list.bufs.begin(); + j != list.bufs.end(); ++j) { scene::IMeshBuffer *buf = *j; driver->drawMeshBuffer(buf); vertex_count += buf->getVertexCount(); meshbuffer_count++; } -#if 0 - /* - Draw the faces of the block - */ - { - //JMutexAutoLock lock(block->mesh_mutex); - - MapBlockMesh *mapBlockMesh = block->mesh; - assert(mapBlockMesh); - - scene::SMesh *mesh = mapBlockMesh->getMesh(); - assert(mesh); - u32 c = mesh->getMeshBufferCount(); - bool stuff_actually_drawn = false; - for(u32 i=0; igetMeshBuffer(i); - const video::SMaterial& material = buf->getMaterial(); - video::IMaterialRenderer* rnd = - driver->getMaterialRenderer(material.MaterialType); - bool transparent = (rnd && rnd->isTransparent()); - // Render transparent on transparent pass and likewise. - if(transparent == is_transparent_pass) - { - if(buf->getVertexCount() == 0) - errorstream<<"Block ["<setMaterial(buf->getMaterial()); - driver->drawMeshBuffer(buf); - vertex_count += buf->getVertexCount(); - meshbuffer_count++; - stuff_actually_drawn = true; - } - } - if(stuff_actually_drawn) - blocks_had_pass_meshbuf++; - else - blocks_without_stuff++; - } -#endif } } // ScopeProfiler diff --git a/src/environment.cpp b/src/environment.cpp index b1372431f..60a26e65f 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2383,13 +2383,16 @@ void ClientEnvironment::step(float dtime) g_profiler->avg("CEnv: num of simple objects", m_simple_objects.size()); for(std::vector::iterator i = m_simple_objects.begin(); i != m_simple_objects.end();) { - ClientSimpleObject *simple = *i; std::vector::iterator cur = i; - ++i; + ClientSimpleObject *simple = *cur; + simple->step(dtime); - if(simple->m_to_be_removed){ + if(simple->m_to_be_removed) { delete simple; - m_simple_objects.erase(cur); + i = m_simple_objects.erase(cur); + } + else { + ++i; } } } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index ba1b16d6a..071c60138 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -417,9 +417,8 @@ void GenerateNotifier::getEvents( std::map > &event_map, bool peek_events) { - std::list::iterator it; - - for (it = m_notify_events.begin(); it != m_notify_events.end(); ++it) { + for (std::vector::iterator it = m_notify_events.begin(); + it != m_notify_events.end(); ++it) { GenNotifyEvent &gn = *it; std::string name = (gn.type == GENNOTIFY_DECORATION) ? "decoration#"+ itos(gn.id) : diff --git a/src/mapgen.h b/src/mapgen.h index 5bbdd724d..f2e63e533 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -91,7 +91,7 @@ public: private: u32 m_notify_on; std::set *m_notify_on_deco_ids; - std::list m_notify_events; + std::vector m_notify_events; }; struct MapgenSpecificParams { diff --git a/src/nodedef.cpp b/src/nodedef.cpp index ac49b4f3c..6cf456e4d 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -443,7 +443,7 @@ private: content_t m_next_id; // List of node strings and node resolver callbacks to perform - std::list m_pending_node_lookups; + std::vector m_pending_node_lookups; // True when all nodes have been registered bool m_node_registration_complete; @@ -479,7 +479,7 @@ void CNodeDefManager::clear() m_next_id = 0; m_node_registration_complete = false; - for (std::list::iterator + for (std::vector::iterator it = m_pending_node_lookups.begin(); it != m_pending_node_lookups.end(); ++it) @@ -1309,7 +1309,7 @@ void CNodeDefManager::pendNodeResolve(NodeResolveInfo *nri) void CNodeDefManager::cancelNodeResolve(NodeResolver *resolver) { - for (std::list::iterator + for (std::vector::iterator it = m_pending_node_lookups.begin(); it != m_pending_node_lookups.end(); ++it) { @@ -1326,7 +1326,7 @@ void CNodeDefManager::runNodeResolverCallbacks() { while (!m_pending_node_lookups.empty()) { NodeResolveInfo *nri = m_pending_node_lookups.front(); - m_pending_node_lookups.pop_front(); + m_pending_node_lookups.erase(m_pending_node_lookups.begin()); nri->resolver->resolveNodeNames(nri); nri->resolver->m_lookup_done = true; delete nri; @@ -1345,7 +1345,7 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri, content_t c; std::string name = nri->nodenames.front(); - nri->nodenames.pop_front(); + nri->nodenames.erase(nri->nodenames.begin()); bool success = getId(name, c); if (!success && node_alt != "") { @@ -1385,7 +1385,7 @@ bool CNodeDefManager::getIdsFromResolveInfo(NodeResolveInfo *nri, content_t c; std::string name = nri->nodenames.front(); - nri->nodenames.pop_front(); + nri->nodenames.erase(nri->nodenames.begin()); if (name.substr(0,6) != "group:") { if (getId(name, c)) { diff --git a/src/nodedef.h b/src/nodedef.h index 52ef29e50..a1c2e1b53 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -309,7 +309,7 @@ struct NodeResolveInfo { resolver = nr; } - std::list nodenames; + std::vector nodenames; std::list nodelistinfo; NodeResolver *resolver; }; diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index f14b0dfcb..54ec69010 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -459,7 +459,7 @@ int ModApiMapgen::l_register_biome(lua_State *L) } NodeResolveInfo *nri = new NodeResolveInfo(b); - std::list &nnames = nri->nodenames; + std::vector &nnames = nri->nodenames; nnames.push_back(getstringfield_default(L, index, "node_top", "")); nnames.push_back(getstringfield_default(L, index, "node_filler", "")); nnames.push_back(getstringfield_default(L, index, "node_stone", "")); -- 2.25.1