Take relative path issue into account when unloading texture
Now except global particle textures all textures loaded by track can be clean properly
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/particle_kind_manager.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
@@ -381,14 +382,26 @@ void MaterialManager::makeMaterialsPermanent()
|
||||
} // makeMaterialsPermanent
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void MaterialManager::unloadAllTextures()
|
||||
{
|
||||
std::string texture_folder = file_manager->getAssetDirectory(FileManager::TEXTURE);
|
||||
std::string texture_folder =
|
||||
file_manager->getAssetDirectory(FileManager::TEXTURE);
|
||||
texture_folder = file_manager->getFileSystem()->getAbsolutePath
|
||||
(texture_folder.c_str()).c_str();
|
||||
core::stringc texfname(texture_folder.c_str());
|
||||
texfname.make_lower();
|
||||
texture_folder = texfname.c_str();
|
||||
for (int i = 0; i < m_shared_material_index; i++)
|
||||
{
|
||||
if (m_materials[i]->getTexFullPath().find(texture_folder) != std::string::npos)
|
||||
m_materials[i]->unloadTexture();
|
||||
// Global particle textures will stay until exit
|
||||
// STK, which avoid hangs when lazy-loading the texture when being
|
||||
// triggered.
|
||||
Material* m = m_materials[i];
|
||||
if (!ParticleKindManager::get()->isGlobalParticleMaterial(m)
|
||||
&& m->getTexFullPath().find(texture_folder) != std::string::npos)
|
||||
{
|
||||
m->unloadTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,3 +124,14 @@ ParticleKind* ParticleKindManager::getParticles(const std::string &name)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool ParticleKindManager::isGlobalParticleMaterial(Material* m) const
|
||||
{
|
||||
for (auto& p : m_kinds)
|
||||
{
|
||||
if (p.second->getMaterial() == m)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class Material;
|
||||
|
||||
/**
|
||||
* \brief Holds and manages a list of all types of particles
|
||||
* \ingroup graphics
|
||||
@@ -45,6 +47,7 @@ public:
|
||||
|
||||
ParticleKind* getParticles(const std::string &name);
|
||||
|
||||
bool isGlobalParticleMaterial(Material* m) const;
|
||||
void cleanUpTrackSpecificGfx();
|
||||
void cleanup();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user