Skip to content

Commit

Permalink
Fix massive memoryleak
Browse files Browse the repository at this point in the history
Destroying entity does not destroy material, texture and mesh associated
with it and are required to be released separately.
  • Loading branch information
latami committed Dec 11, 2016
1 parent 7dea0a5 commit 178f298
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions HeightMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ void HeightMap::load(Ogre::SceneNode *node, Ogre::SceneManager *scene,
void HeightMap::unload(Ogre::SceneNode *node, Ogre::SceneManager *scene)
{
node->detachObject(this->entity->getName());

std::string mshName = this->entity->getMesh()->getName();
std::string texName = this->entity->getName() + "_texture";
std::string matName = this->entity->getName() + "_material";

// Unload and remove material, texture and mesh.
Ogre::MaterialManager::getSingleton().remove(matName);
Ogre::TextureManager::getSingleton().remove(texName);
Ogre::MeshManager::getSingleton().remove(mshName);

scene->destroyEntity(this->entity->getName());
this->entity = NULL;
}
Expand Down

0 comments on commit 178f298

Please sign in to comment.