diff options
author | sapier <Sapier at GMX dot net> | 2013-04-07 20:13:21 +0200 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-04-07 21:51:35 -0400 |
commit | 3b684d306c74f012cb066e6b256325edaefbf470 (patch) | |
tree | 524c1045776ec71d21168010a66c16cbabb484de /src | |
parent | e1146396bc043782b288226c027bc28857ccf4d2 (diff) | |
download | minetest-3b684d306c74f012cb066e6b256325edaefbf470.tar.gz minetest-3b684d306c74f012cb066e6b256325edaefbf470.tar.bz2 minetest-3b684d306c74f012cb066e6b256325edaefbf470.zip |
fix 3d model mesh leak
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp index 1d5f8f472..4b14125cd 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -363,6 +363,15 @@ Client::~Client() for (std::list<MediaFetchThread*>::iterator i = m_media_fetch_threads.begin(); i != m_media_fetch_threads.end(); ++i) delete *i; + + // cleanup 3d model meshes on client shutdown + while (m_device->getSceneManager()->getMeshCache()->getMeshCount() != 0) { + scene::IAnimatedMesh * mesh = + m_device->getSceneManager()->getMeshCache()->getMeshByIndex(0); + + if (mesh != NULL) + m_device->getSceneManager()->getMeshCache()->removeMesh(mesh); + } } void Client::connect(Address address) @@ -976,14 +985,26 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) { verbosestream<<"Client: Storing model into Irrlicht: " <<"\""<<filename<<"\""<<std::endl; + scene::ISceneManager *smgr = m_device->getSceneManager(); + + //check if mesh was already cached + scene::IAnimatedMesh *mesh = + smgr->getMeshCache()->getMeshByName(filename.c_str()); + + if (mesh != NULL) { + errorstream << "Multiple models with name: " << filename.c_str() << + " found replacing previous model!" << std::endl; + + smgr->getMeshCache()->removeMesh(mesh); + mesh = 0; + } io::IFileSystem *irrfs = m_device->getFileSystem(); io::IReadFile *rfile = irrfs->createMemoryReadFile( *data_rw, data_rw.getSize(), filename.c_str()); assert(rfile); - scene::ISceneManager *smgr = m_device->getSceneManager(); - scene::IAnimatedMesh *mesh = smgr->getMesh(rfile); + mesh = smgr->getMesh(rfile); smgr->getMeshCache()->addMesh(filename.c_str(), mesh); return true; |