From 3638d15558ece56407d311fc35625a89020aa67d Mon Sep 17 00:00:00 2001 From: darkrose Date: Mon, 5 Oct 2015 03:54:07 +1000 Subject: [PATCH] let's see if this improves the segfault situation --- src/content_mapblock.cpp | 38 ++++++++++++++++++-------------------- src/map.cpp | 24 +++++++++++++++++++++--- src/map.h | 1 + src/nodemetadata.cpp | 18 ++++++++++++++++-- src/nodemetadata.h | 5 ++++- 5 files changed, 60 insertions(+), 26 deletions(-) diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index 81c56f7..cdc5936 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -1970,11 +1970,7 @@ void meshgen_nodebox(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, boo }; TileSpec tiles[6]; - NodeMetadata *meta = data->m_env->getMap().getNodeMetadata(p+data->m_blockpos_nodes); - if (meta) { - NodeMetadata *cmeta = meta->clone(); - meta = cmeta; - } + NodeMetadata *meta = data->m_env->getMap().getNodeMetadataClone(p+data->m_blockpos_nodes); for (int i = 0; i < 6; i++) { // Handles facedir rotation for textures tiles[i] = getNodeTile(n,p,tile_dirs[i],data->m_temp_mods,meta); @@ -3805,16 +3801,19 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo cols[2] = 64; cols[3] = 255; }else{ - NodeMetadata *meta = data->m_env->getMap().getNodeMetadata(p+data->m_blockpos_nodes); - if (meta && meta->getEnergy()) { - u8 e = meta->getEnergy(); - e = (e*16)-1; - if (e < 80) - e = 80; - cols[0] = 255; - cols[1] = e; - cols[2] = e; - cols[3] = e; + NodeMetadata *meta = data->m_env->getMap().getNodeMetadataClone(p+data->m_blockpos_nodes); + if (meta) { + if (meta->getEnergy()) { + u8 e = meta->getEnergy(); + e = (e*16)-1; + if (e < 80) + e = 80; + cols[0] = 255; + cols[1] = e; + cols[2] = e; + cols[3] = e; + } + delete meta; } } @@ -4068,10 +4067,9 @@ void meshgen_stairlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected) } TileSpec tiles[6]; - NodeMetadata *meta = data->m_env->getMap().getNodeMetadata(p+data->m_blockpos_nodes); for (int i=0; i<6; i++) { // Handles facedir rotation for textures - tiles[i] = getNodeTile(n,p,faces[i],data->m_temp_mods,meta); + tiles[i] = getNodeTile(n,p,faces[i],data->m_temp_mods); } bool urot = (n.getContent() >= CONTENT_SLAB_STAIR_UD_MIN && n.getContent() <= CONTENT_SLAB_STAIR_UD_MAX); @@ -4380,10 +4378,9 @@ void meshgen_slablike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected) }; TileSpec tiles[6]; - NodeMetadata *meta = data->m_env->getMap().getNodeMetadata(p+data->m_blockpos_nodes); for (int i = 0; i < 6; i++) { // Handles facedir rotation for textures - tiles[i] = getNodeTile(n,p,faces[i],data->m_temp_mods,meta); + tiles[i] = getNodeTile(n,p,faces[i],data->m_temp_mods); } v3f pos = intToFloat(p, BS); @@ -5173,7 +5170,7 @@ void meshgen_flaglike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected) TileSpec tiles[6]; TileSpec flag; MapNode pn(CONTENT_FENCE); - NodeMetadata *meta = data->m_env->getMap().getNodeMetadata(p+data->m_blockpos_nodes); + NodeMetadata *meta = data->m_env->getMap().getNodeMetadataClone(p+data->m_blockpos_nodes); for (u16 i=0; i<6; i++) { // Handles facedir rotation for textures tiles[i] = getNodeTile(pn,p,tile_dirs[i],data->m_temp_mods); @@ -5225,6 +5222,7 @@ void meshgen_flaglike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected) } data->append(flag.getMaterial(), vertices, 4, indices, 6, colours); + delete meta; } void meshgen_melonlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected) diff --git a/src/map.cpp b/src/map.cpp index c0324a1..cc3b4c8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1621,13 +1621,12 @@ NodeMetadata* Map::getNodeMetadata(v3s16 p) v3s16 blockpos = getNodeBlockPos(p); v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE; MapBlock *block = getBlockNoCreateNoEx(blockpos); - if(!block){ + if (!block) { infostream<<"Map::getNodeMetadata(): Need to emerge " <m_node_metadata.getClone(p_rel); + return meta; +} + void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta) { v3s16 blockpos = getNodeBlockPos(p); diff --git a/src/map.h b/src/map.h index 196a393..f2553e2 100644 --- a/src/map.h +++ b/src/map.h @@ -279,6 +279,7 @@ public: */ NodeMetadata* getNodeMetadata(v3s16 p); + NodeMetadata* getNodeMetadataClone(v3s16 p); void setNodeMetadata(v3s16 p, NodeMetadata *meta); void removeNodeMetadata(v3s16 p); void nodeMetadataStep(float dtime, diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index e63abd8..608dcd9 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -184,6 +184,11 @@ void NodeMetadataList::deSerialize(std::istream &is) } } +NodeMetadataList::NodeMetadataList() +{ + m_mutex.Init(); +} + NodeMetadataList::~NodeMetadataList() { for(core::map::Iterator @@ -202,12 +207,21 @@ NodeMetadata* NodeMetadataList::get(v3s16 p) return NULL; return n->getValue(); } +NodeMetadata *NodeMetadataList::getClone(v3s16 p) +{ + JMutexAutoLock lock(m_mutex); + NodeMetadata *data = get(p); + if (!data) + return NULL; + + return data->clone(); +} void NodeMetadataList::remove(v3s16 p) { + JMutexAutoLock lock(m_mutex); NodeMetadata *olddata = get(p); - if(olddata) - { + if (olddata) { delete olddata; m_data.remove(p); } diff --git a/src/nodemetadata.h b/src/nodemetadata.h index 249785f..89fd613 100644 --- a/src/nodemetadata.h +++ b/src/nodemetadata.h @@ -116,13 +116,15 @@ private: class NodeMetadataList { public: + NodeMetadataList(); ~NodeMetadataList(); void serialize(std::ostream &os); void deSerialize(std::istream &is); // Get pointer to data - NodeMetadata* get(v3s16 p); + NodeMetadata *get(v3s16 p); + NodeMetadata *getClone(v3s16 p); // Deletes data void remove(v3s16 p); // Deletes old data and sets a new one @@ -134,6 +136,7 @@ public: private: core::map m_data; + JMutex m_mutex; }; #endif