Implement cleaning for new texture
Also warn if there is possible texture leaking when exit STK
This commit is contained in:
parent
555cdacd83
commit
ba8846522e
@ -52,6 +52,11 @@ FontWithFace::FontWithFace(const std::string& name, FaceTTF* ttf)
|
||||
*/
|
||||
FontWithFace::~FontWithFace()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_spritebank->getTextureCount(); i++)
|
||||
{
|
||||
STKTexManager::getInstance()->removeTexture(
|
||||
static_cast<STKTexture*>(m_spritebank->getTexture(i)));
|
||||
}
|
||||
m_spritebank->drop();
|
||||
m_spritebank = NULL;
|
||||
|
||||
|
@ -161,11 +161,10 @@ IrrDriver::IrrDriver()
|
||||
IrrDriver::~IrrDriver()
|
||||
{
|
||||
assert(m_device != NULL);
|
||||
STKTexManager::getInstance()->kill();
|
||||
m_device->drop();
|
||||
m_device = NULL;
|
||||
m_modes.clear();
|
||||
|
||||
STKTexManager::getInstance()->kill();
|
||||
#ifndef SERVER_ONLY
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
@ -1431,6 +1430,12 @@ void IrrDriver::removeMeshFromCache(scene::IMesh *mesh)
|
||||
*/
|
||||
void IrrDriver::removeTexture(video::ITexture *t)
|
||||
{
|
||||
STKTexture* stkt = dynamic_cast<STKTexture*>(t);
|
||||
if (stkt)
|
||||
{
|
||||
STKTexManager::getInstance()->removeTexture(stkt);
|
||||
return;
|
||||
}
|
||||
m_video_driver->removeTexture(t);
|
||||
} // removeTexture
|
||||
|
||||
@ -1676,29 +1681,6 @@ video::ITexture *IrrDriver::getTexture(const std::string &filename,
|
||||
return STKTexManager::getInstance()->getTexture(filename);
|
||||
} // getTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Clear the texture-filename reminder.
|
||||
*/
|
||||
void IrrDriver::clearTexturesFileName()
|
||||
{
|
||||
m_texturesFileName.clear();
|
||||
} // clearTexturesFileName
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Get the texture file name using a texture pointer.
|
||||
* \param tex Pointer on the texture for which we want to find the file name.
|
||||
* \return Filename of the texture if found, or an empty string otherwise.
|
||||
*/
|
||||
std::string IrrDriver::getTextureName(video::ITexture* tex)
|
||||
{
|
||||
std::map<video::ITexture*, std::string>::iterator it;
|
||||
it = m_texturesFileName.find(tex);
|
||||
if (it != m_texturesFileName.end())
|
||||
return it->second;
|
||||
else
|
||||
return "";
|
||||
} // getTextureName
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Appends a pointer to each texture used in this mesh to the vector.
|
||||
* \param mesh The mesh from which the textures are being determined.
|
||||
|
@ -111,10 +111,6 @@ private:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** Keep a trace of the origin file name of a texture. */
|
||||
std::map<video::ITexture*, std::string> m_texturesFileName;
|
||||
|
||||
/** Flag to indicate if a resolution change is pending (which will be
|
||||
* acted upon in the next update). None means no change, yes means
|
||||
* change to new resolution and trigger confirmation dialog.
|
||||
@ -235,8 +231,6 @@ public:
|
||||
bool is_premul=false,
|
||||
bool is_prediv=false,
|
||||
bool complain_if_not_found=true);
|
||||
void clearTexturesFileName();
|
||||
std::string getTextureName(video::ITexture* tex);
|
||||
void grabAllTextures(const scene::IMesh *mesh);
|
||||
void dropAllTextures(const scene::IMesh *mesh);
|
||||
scene::IMesh *createQuadMesh(const video::SMaterial *material=NULL,
|
||||
|
@ -26,6 +26,7 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
STKTexManager::~STKTexManager()
|
||||
{
|
||||
removeTexture(NULL/*texture*/, true/*remove_all*/);
|
||||
} // ~STKTexManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -87,11 +88,47 @@ video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
|
||||
} // getTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void STKTexManager::addTexture(STKTexture* t)
|
||||
void STKTexManager::addTexture(STKTexture* texture)
|
||||
{
|
||||
m_all_textures[t->getName().getPtr()] = t;
|
||||
m_all_textures[texture->getName().getPtr()] = texture;
|
||||
} // addTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void STKTexManager::removeTexture(STKTexture* texture, bool remove_all)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::vector<std::string> undeleted_texture;
|
||||
#endif
|
||||
auto p = m_all_textures.begin();
|
||||
while (p != m_all_textures.end())
|
||||
{
|
||||
if (remove_all || p->second == texture)
|
||||
{
|
||||
if (remove_all && p->second == NULL)
|
||||
{
|
||||
p = m_all_textures.erase(p);
|
||||
continue;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (remove_all && p->second->getReferenceCount() != 1)
|
||||
undeleted_texture.push_back(p->second->getName().getPtr());
|
||||
#endif
|
||||
p->second->drop();
|
||||
p = m_all_textures.erase(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
p++;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
for (const std::string& s : undeleted_texture)
|
||||
{
|
||||
Log::error("STKTexManager", "%s undeleted!", s.c_str());
|
||||
}
|
||||
#endif
|
||||
} // removeTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void STKTexManager::dumpAllTexture(bool mesh_texture)
|
||||
{
|
||||
|
@ -57,9 +57,9 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c);
|
||||
// ------------------------------------------------------------------------
|
||||
void addTexture(STKTexture* t);
|
||||
void addTexture(STKTexture* texture);
|
||||
// ------------------------------------------------------------------------
|
||||
void removeTexture(STKTexture* t);
|
||||
void removeTexture(STKTexture* texture, bool remove_all = false);
|
||||
// ------------------------------------------------------------------------
|
||||
void dumpAllTexture(bool mesh_texture);
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -296,9 +296,6 @@ void Track::cleanup()
|
||||
ParticleKindManager::get()->cleanUpTrackSpecificGfx();
|
||||
#endif
|
||||
|
||||
// Clear reminder of the link between textures and file names.
|
||||
irr_driver->clearTexturesFileName();
|
||||
|
||||
for (unsigned int i = 0; i < m_animated_textures.size(); i++)
|
||||
{
|
||||
delete m_animated_textures[i];
|
||||
|
Loading…
x
Reference in New Issue
Block a user