let's see if this improves the segfault situation

This commit is contained in:
darkrose 2015-10-05 03:54:07 +10:00
parent 7ea5f61a69
commit 3638d15558
5 changed files with 60 additions and 26 deletions

View File

@ -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)

View File

@ -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 "
<<PP(blockpos)<<std::endl;
block = emergeBlock(blockpos, false);
}
if(!block)
{
if (!block) {
infostream<<"WARNING: Map::getNodeMetadata(): Block not found"
<<std::endl;
return NULL;
@ -1636,6 +1635,25 @@ NodeMetadata* Map::getNodeMetadata(v3s16 p)
return meta;
}
NodeMetadata* Map::getNodeMetadataClone(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if (!block) {
infostream<<"Map::getNodeMetadata(): Need to emerge "
<<PP(blockpos)<<std::endl;
block = emergeBlock(blockpos, false);
}
if (!block) {
infostream<<"WARNING: Map::getNodeMetadata(): Block not found"
<<std::endl;
return NULL;
}
NodeMetadata *meta = block->m_node_metadata.getClone(p_rel);
return meta;
}
void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta)
{
v3s16 blockpos = getNodeBlockPos(p);

View File

@ -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,

View File

@ -184,6 +184,11 @@ void NodeMetadataList::deSerialize(std::istream &is)
}
}
NodeMetadataList::NodeMetadataList()
{
m_mutex.Init();
}
NodeMetadataList::~NodeMetadataList()
{
for(core::map<v3s16, NodeMetadata*>::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);
}

View File

@ -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<v3s16, NodeMetadata*> m_data;
JMutex m_mutex;
};
#endif