Skip to content

Commit 3b684d3

Browse files
sapierkwolekr
sapier
authored andcommittedApr 8, 2013
fix 3d model mesh leak
1 parent e114639 commit 3b684d3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed
 

‎src/client.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ Client::~Client()
363363
for (std::list<MediaFetchThread*>::iterator i = m_media_fetch_threads.begin();
364364
i != m_media_fetch_threads.end(); ++i)
365365
delete *i;
366+
367+
// cleanup 3d model meshes on client shutdown
368+
while (m_device->getSceneManager()->getMeshCache()->getMeshCount() != 0) {
369+
scene::IAnimatedMesh * mesh =
370+
m_device->getSceneManager()->getMeshCache()->getMeshByIndex(0);
371+
372+
if (mesh != NULL)
373+
m_device->getSceneManager()->getMeshCache()->removeMesh(mesh);
374+
}
366375
}
367376

368377
void Client::connect(Address address)
@@ -976,14 +985,26 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
976985
{
977986
verbosestream<<"Client: Storing model into Irrlicht: "
978987
<<"\""<<filename<<"\""<<std::endl;
988+
scene::ISceneManager *smgr = m_device->getSceneManager();
989+
990+
//check if mesh was already cached
991+
scene::IAnimatedMesh *mesh =
992+
smgr->getMeshCache()->getMeshByName(filename.c_str());
993+
994+
if (mesh != NULL) {
995+
errorstream << "Multiple models with name: " << filename.c_str() <<
996+
" found replacing previous model!" << std::endl;
997+
998+
smgr->getMeshCache()->removeMesh(mesh);
999+
mesh = 0;
1000+
}
9791001

9801002
io::IFileSystem *irrfs = m_device->getFileSystem();
9811003
io::IReadFile *rfile = irrfs->createMemoryReadFile(
9821004
*data_rw, data_rw.getSize(), filename.c_str());
9831005
assert(rfile);
9841006

985-
scene::ISceneManager *smgr = m_device->getSceneManager();
986-
scene::IAnimatedMesh *mesh = smgr->getMesh(rfile);
1007+
mesh = smgr->getMesh(rfile);
9871008
smgr->getMeshCache()->addMesh(filename.c_str(), mesh);
9881009

9891010
return true;

0 commit comments

Comments
 (0)