Skip to content

Commit

Permalink
Fix issue #2441: crash on respawn, since a conversion std::list to st…
Browse files Browse the repository at this point in the history
…d::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
  • Loading branch information
nerzhul committed Mar 5, 2015
1 parent 0d1eedc commit 9749d9f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 84 deletions.
85 changes: 17 additions & 68 deletions src/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
struct MeshBufList
{
video::SMaterial m;
std::list<scene::IMeshBuffer*> bufs;
std::vector<scene::IMeshBuffer*> bufs;
};

struct MeshBufListList
{
std::list<MeshBufList> lists;
std::vector<MeshBufList> lists;

void clear()
{
Expand All @@ -405,7 +405,7 @@ struct MeshBufListList

void add(scene::IMeshBuffer *buf)
{
for(std::list<MeshBufList>::iterator i = lists.begin();
for(std::vector<MeshBufList>::iterator i = lists.begin();
i != lists.end(); ++i){
MeshBufList &l = *i;
video::SMaterial &m = buf->getMaterial();
Expand Down Expand Up @@ -595,86 +595,35 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
}
}

std::list<MeshBufList> &lists = drawbufs.lists;
std::vector<MeshBufList> &lists = drawbufs.lists;

int timecheck_counter = 0;
for(std::list<MeshBufList>::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;
}
for(std::vector<MeshBufList>::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;
}
}

MeshBufList &list = *i;

driver->setMaterial(list.m);

for(std::list<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
j != list.bufs.end(); ++j)
{
for(std::vector<scene::IMeshBuffer*>::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; i<c; i++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(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 ["<<analyze_block(block)
<<"] contains an empty meshbuf"<<std::endl;
/*
This *shouldn't* hurt too much because Irrlicht
doesn't change opengl textures if the old
material has the same texture.
*/
driver->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

Expand Down
11 changes: 7 additions & 4 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2383,13 +2383,16 @@ void ClientEnvironment::step(float dtime)
g_profiler->avg("CEnv: num of simple objects", m_simple_objects.size());
for(std::vector<ClientSimpleObject*>::iterator
i = m_simple_objects.begin(); i != m_simple_objects.end();) {
ClientSimpleObject *simple = *i;
std::vector<ClientSimpleObject*>::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;
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,8 @@ void GenerateNotifier::getEvents(
std::map<std::string, std::vector<v3s16> > &event_map,
bool peek_events)
{
std::list<GenNotifyEvent>::iterator it;

for (it = m_notify_events.begin(); it != m_notify_events.end(); ++it) {
for (std::vector<GenNotifyEvent>::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) :
Expand Down
2 changes: 1 addition & 1 deletion src/mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class GenerateNotifier {
private:
u32 m_notify_on;
std::set<u32> *m_notify_on_deco_ids;
std::list<GenNotifyEvent> m_notify_events;
std::vector<GenNotifyEvent> m_notify_events;
};

struct MapgenSpecificParams {
Expand Down
12 changes: 6 additions & 6 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class CNodeDefManager: public IWritableNodeDefManager {
content_t m_next_id;

// List of node strings and node resolver callbacks to perform
std::list<NodeResolveInfo *> m_pending_node_lookups;
std::vector<NodeResolveInfo *> m_pending_node_lookups;

// True when all nodes have been registered
bool m_node_registration_complete;
Expand Down Expand Up @@ -479,7 +479,7 @@ void CNodeDefManager::clear()
m_next_id = 0;

m_node_registration_complete = false;
for (std::list<NodeResolveInfo *>::iterator
for (std::vector<NodeResolveInfo *>::iterator
it = m_pending_node_lookups.begin();
it != m_pending_node_lookups.end();
++it)
Expand Down Expand Up @@ -1309,7 +1309,7 @@ void CNodeDefManager::pendNodeResolve(NodeResolveInfo *nri)

void CNodeDefManager::cancelNodeResolve(NodeResolver *resolver)
{
for (std::list<NodeResolveInfo *>::iterator
for (std::vector<NodeResolveInfo *>::iterator
it = m_pending_node_lookups.begin();
it != m_pending_node_lookups.end();
++it) {
Expand All @@ -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;
Expand All @@ -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 != "") {
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ struct NodeResolveInfo {
resolver = nr;
}

std::list<std::string> nodenames;
std::vector<std::string> nodenames;
std::list<NodeListInfo> nodelistinfo;
NodeResolver *resolver;
};
Expand Down
2 changes: 1 addition & 1 deletion src/script/lua_api/l_mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ int ModApiMapgen::l_register_biome(lua_State *L)
}

NodeResolveInfo *nri = new NodeResolveInfo(b);
std::list<std::string> &nnames = nri->nodenames;
std::vector<std::string> &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", ""));
Expand Down

0 comments on commit 9749d9f

Please sign in to comment.