diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index a7be11da2..4f9f462f9 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -179,9 +179,10 @@ void Track::cleanup() if(UserConfigParams::logMemory()) { - printf("[memory] Number of meshes in cache after cleaning up '%s': %d.\n", + printf("[memory] After cleaning '%s': mesh cache %d texture cache %d\n", getIdent().c_str(), - irr_driver->getSceneManager()->getMeshCache()->getMeshCount()); + irr_driver->getSceneManager()->getMeshCache()->getMeshCount(), + irr_driver->getVideoDriver()->getTextureCount()); #ifdef DEBUG scene::IMeshCache *cache = irr_driver->getSceneManager()->getMeshCache(); for(unsigned int i=0; igetMeshCount(); i++) @@ -198,6 +199,24 @@ void Track::cleanup() name.getInternalName().c_str()); } // if name not found } // for i < cache size + + video::IVideoDriver *vd = irr_driver->getVideoDriver(); + for(unsigned int i=0; igetTextureCount(); i++) + { + video::ITexture *t = vd->getTextureByIndex(i); + std::vector::iterator p; + p = std::find(m_all_used_textures.begin(), m_all_used_textures.end(), + t); + if(p!=m_all_used_textures.end()) + { + m_all_used_textures.erase(p); + } + else + { + printf("[memory] Leaked texture '%s'.\n", + t->getName().getInternalName().c_str()); + } + } #endif } // if verbose @@ -964,9 +983,10 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id) assert(m_all_cached_meshes.size()==0); if(UserConfigParams::logMemory()) { - printf("[memory] Number of meshes in cache before loading '%s': %d.\n", - getIdent().c_str(), - irr_driver->getSceneManager()->getMeshCache()->getMeshCount()); + printf("[memory] Before loading '%s': mesh cache %d texture cache %d\n", + getIdent().c_str(), + irr_driver->getSceneManager()->getMeshCache()->getMeshCount(), + irr_driver->getVideoDriver()->getTextureCount()); #ifdef DEBUG scene::IMeshCache *cache = irr_driver->getSceneManager()->getMeshCache(); m_old_mesh_buffers.clear(); @@ -975,6 +995,14 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id) const io::SNamedPath &name=cache->getMeshName(i); m_old_mesh_buffers.push_back(name.getInternalName().c_str()); } + + m_all_used_textures.clear(); + video::IVideoDriver *vd = irr_driver->getVideoDriver(); + for(unsigned int i=0; igetTextureCount(); i++) + { + video::ITexture *t=vd->getTextureByIndex(i); + m_all_used_textures.push_back(t); + } #endif } @@ -1288,9 +1316,10 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id) } if(UserConfigParams::logMemory()) - printf("[memory] Number of meshes in cache after loading '%s': %d.\n", + printf("[memory] After loading '%s': mesh cache %d texture cache %d\n", getIdent().c_str(), - irr_driver->getSceneManager()->getMeshCache()->getMeshCount()); + irr_driver->getSceneManager()->getMeshCache()->getMeshCount(), + irr_driver->getVideoDriver()->getTextureCount()); } // loadTrackModel diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 9305bfe53..2945d9299 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -83,6 +83,9 @@ private: /** The list of all meshes that are loaded from disk, which means * that those meshes are being cached by irrlicht, and need to be freed. */ std::vector m_all_cached_meshes; + /** A list of textures to help in removing unused textures from irrlicht's + * texture cache after cleanup. */ + std::vector m_all_used_textures; #ifdef DEBUG /** Used to store all buffers in irrlicht's memory cache before a track * is loaded. After cleanup of a track we can test which meshes are