Properly freed some memory. Big question: why on earth

do we load e.g. parachute.b3d twice??


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8021 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2011-03-22 11:11:56 +00:00
parent fa512b8010
commit 3e9c1d4294
3 changed files with 34 additions and 9 deletions

View File

@@ -53,6 +53,23 @@ initAttachmentType iat[]=
{ATTACH_MAX, "", "" },
};
//-----------------------------------------------------------------------------
AttachmentManager::~AttachmentManager()
{
for(int i=0; iat[i].attachment!=ATTACH_MAX; i++)
{
scene::IMesh *mesh = m_attachments[iat[i].attachment];
mesh->drop();
// If the count is 1, the only reference is in the
// irrlicht mesh cache, so the mesh can be removed
// from the cache.
// Note that this test is necessary, since some meshes
// are also used in powerup_manager!!!
if(mesh->getReferenceCount()==1)
irr_driver->removeMesh(mesh);
}
} // ~AttachmentManager
//-----------------------------------------------------------------------------
void AttachmentManager::removeTextures()
{
@@ -67,10 +84,9 @@ void AttachmentManager::loadModels()
{
for(int i=0; iat[i].attachment!=ATTACH_MAX; i++)
{
// FIXME LEAK: these models are not removed (unimportant, since they
// have to be in memory till the end of the game.
std::string full_path = file_manager->getModelFile(iat[i].file);
m_attachments[iat[i].attachment]=irr_driver->getAnimatedMesh(full_path);
m_attachments[iat[i].attachment]->grab();
if(iat[i].icon_file)
{
std::string full_icon_path =

View File

@@ -32,12 +32,13 @@ private:
scene::IAnimatedMesh *m_attachments[ATTACH_MAX];
Material *m_all_icons [ATTACH_MAX];
public:
AttachmentManager() {};
AttachmentManager() {};
~AttachmentManager();
void removeTextures ();
void loadModels ();
/** Returns the mest for a certain attachment.
* \param type Type of the attachment needed. */
scene::IAnimatedMesh *getMesh(attachmentType type) const {return m_attachments[type]; }
void removeTextures ();
void loadModels ();
/** Returns the icon to display in the race gui if a kart
* has an attachment. */
const Material*

View File

@@ -54,8 +54,18 @@ PowerupManager::~PowerupManager()
{
for(unsigned int i=POWERUP_FIRST; i<=POWERUP_LAST; i++)
{
if(m_all_meshes[(PowerupType)i])
m_all_meshes[(PowerupType)i]->drop();
scene::IMesh *mesh = m_all_meshes[(PowerupType)i];
if(mesh)
{
mesh->drop();
// If the ref count is 1, the only reference is in
// irrlicht's mesh cache, from which the mesh can
// then be deleted
// Note that this test is necessary, since some meshes
// are also used in attachment_manager!!!
if(mesh->getReferenceCount()==1)
m_all_meshes[(PowerupType)i]->drop();
}
}
} // ~PowerupManager
@@ -156,8 +166,6 @@ void PowerupManager::LoadPowerup(PowerupType type, const XMLNode &node)
node.get("model", &model);
if(model.size()>0)
{
// FIXME LEAK: not freed (unimportant, since the models have to exist
// for the whole game anyway).
std::string full_path = file_manager->getModelFile(model);
m_all_meshes[type] = irr_driver->getMesh(full_path);
if(!m_all_meshes[type])