Bugfix: icons for powerups were not permanent (unless they are listed in

materials.dat), which cause them to be deleted after one race, causing
the powerup_manager to have invalid pointers.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2474 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-11-19 02:08:00 +00:00
parent c859947a93
commit 847612a561
3 changed files with 21 additions and 4 deletions

View File

@ -118,7 +118,9 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
lisp->get("icon", sIconFile );
// load material
m_all_icons[collectType] = material_manager->getMaterial(sIconFile);
m_all_icons[collectType] = material_manager->getMaterial(sIconFile,
/* full_path */ false,
/*make_permanent */ true);
m_all_icons[collectType]->getState()->ref();
if(sModel!="")

View File

@ -195,8 +195,22 @@ Material *MaterialManager::getMaterial ( ssgLeaf *l )
} // getMaterial
//-----------------------------------------------------------------------------
/** Returns the material of a given name, if it doesn't exist, it is loaded.
* Materials that are just loaded are not permanent, and so get deleted after
* a race (this is used to load temporary, track specific materials). To make
* material permanent, make_permanent must be set to true. This is used for
* the powerup_manager, since not all icons for the powerups are listed in the
* materials.dat file, causing the missing ones to be temporary only (and
* then get deleted after one race, causing the powerup_manager to have
* invalid pointers.
* \param fname Name of the material.
* \param is_full_path True if the name includes the path (defaults to false)
* \param make_permanent True if this material should be kept in memory
* (defaults to false)
*/
Material *MaterialManager::getMaterial(const std::string& fname,
bool is_full_path )
bool is_full_path,
bool make_permanent)
{
if(fname=="")
{
@ -220,7 +234,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
// Add the new material
Material* m=new Material(fname,"", (int)m_materials.size(), is_full_path);
m_materials.push_back(m);
if(make_permanent) m_shared_material_index = (int)m_materials.size();
return m ;
} // getMaterial

View File

@ -42,7 +42,8 @@ public:
void reInit ();
int addEntity (Material *m);
Material *getMaterial (ssgLeaf *lf);
Material *getMaterial (const std::string& t, bool is_full_path=false);
Material *getMaterial (const std::string& t, bool is_full_path=false,
bool make_permanent=false);
void addSharedMaterial(const std::string& filename);
bool pushTempMaterial (const std::string& filename);
void popTempMaterial ();