Fix memory leak of mesh tool
This commit is contained in:
parent
965e901796
commit
e09fe6ff8a
@ -444,29 +444,27 @@ scene::IMesh* MeshTools::createMeshWithTangents(scene::IMesh* mesh,
|
||||
clone->recalculateBoundingBox();
|
||||
if (calculate_tangents)
|
||||
recalculateTangents(clone, recalculate_normals, smooth, angle_weighted);
|
||||
|
||||
int mbcount = clone->getMeshBufferCount();
|
||||
for (int i = 0; i < mbcount; i++)
|
||||
{
|
||||
scene::IMeshBuffer* mb = clone->getMeshBuffer(i);
|
||||
|
||||
for (u32 t = 0; t < video::MATERIAL_MAX_TEXTURES; t++)
|
||||
{
|
||||
video::ITexture* texture = mb->getMaterial().TextureLayer[t].Texture;
|
||||
if (texture != NULL)
|
||||
texture->grab();
|
||||
}
|
||||
}
|
||||
|
||||
scene::IMeshCache* meshCache = irr_driver->getSceneManager()->getMeshCache();
|
||||
io::SNamedPath path = meshCache->getMeshName(mesh);
|
||||
irr_driver->removeMeshFromCache(mesh);
|
||||
if (path.getPath() == "")
|
||||
{
|
||||
// This mesh is not in irrlicht cache, drop it directly
|
||||
assert(mesh->getReferenceCount() == 1);
|
||||
mesh->drop();
|
||||
return clone;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cache the calcuated tangent mesh with path
|
||||
irr_driver->removeMeshFromCache(mesh);
|
||||
scene::SAnimatedMesh* amesh = new scene::SAnimatedMesh(clone);
|
||||
clone->drop();
|
||||
irr_driver->grabAllTextures(amesh);
|
||||
meshCache->addMesh(path, amesh);
|
||||
World::getWorld()->getTrack()->addCachedMesh(amesh);
|
||||
|
||||
scene::SAnimatedMesh* amesh = new scene::SAnimatedMesh(clone);
|
||||
meshCache->addMesh(path, amesh);
|
||||
return amesh;
|
||||
}
|
||||
|
||||
World::getWorld()->getTrack()->addCachedMesh(amesh);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
@ -1174,7 +1174,7 @@ bool Track::loadMainTrack(const XMLNode &root)
|
||||
handleAnimatedTextures(scene_node, *track_node);
|
||||
m_all_nodes.push_back(scene_node);
|
||||
|
||||
MeshTools::minMax3D(merged_mesh, &m_aabb_min, &m_aabb_max);
|
||||
MeshTools::minMax3D(tangent_mesh, &m_aabb_min, &m_aabb_max);
|
||||
// Increase the maximum height of the track: since items that fly
|
||||
// too high explode, e.g. cakes can not be show when being at the
|
||||
// top of the track (since they will explode when leaving the AABB
|
||||
|
Loading…
Reference in New Issue
Block a user