Use absolute paths to lookup materials, fixes karts with identical texture names being in conflict. Also, when a texture is misisng, log an error but don't abort

This commit is contained in:
Marianne Gagnon 2015-01-11 20:15:37 -05:00
parent 8798eda41b
commit 81bd79a736
4 changed files with 22 additions and 3 deletions

View File

@ -65,6 +65,8 @@ Material::Material(const XMLNode *node, bool deprecated)
throw std::runtime_error("[Material] No texture name specified "
"in file\n");
}
m_full_path = file_manager->getFileSystem()->getAbsolutePath(
file_manager->searchTexture(m_texname).c_str()).c_str();
init();
node->get("lazy-load", &m_lazy_load);
@ -404,6 +406,8 @@ Material::Material(const std::string& fname, bool is_full_path,
m_texname = fname;
init();
m_full_path = file_manager->getFileSystem()->getAbsolutePath(
file_manager->searchTexture(m_texname).c_str()).c_str();
if (load_texture)
install(is_full_path, complain_if_not_found);

View File

@ -85,6 +85,8 @@ private:
/** Name of the texture. */
std::string m_texname;
std::string m_full_path;
/** If true, the texture will not automatically be loaded and bound
* at load time, it must be loaded elsewhere. This is used to store
* material settings for font textures, without loading fonts for
@ -288,6 +290,9 @@ public:
// ------------------------------------------------------------------------
const std::string&
getTexFname () const { return m_texname; }
// ------------------------------------------------------------------------
const std::string&
getTexFullPath () const { return m_full_path; }
// ------------------------------------------------------------------------
bool isTransparent () const

View File

@ -69,8 +69,17 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
if (t == NULL)
return m_default_material;
const std::string image = StringUtils::getBasename(core::stringc(t->getName()).c_str());
core::stringc img_path = core::stringc(t->getName());
const std::string image = StringUtils::getBasename(img_path.c_str());
// Search backward so that temporary (track) textures are found first
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
{
std::string full_path = m_materials[i]->getTexFullPath();
if (m_materials[i]->getTexFullPath() == img_path.c_str())
{
return m_materials[i];
}
}
for(int i = (int)m_materials.size()-1; i>=0; i-- )
{
if (m_materials[i]->getTexFname()==image)

View File

@ -283,8 +283,9 @@ SetTexture(GLMesh &mesh, unsigned i, bool isSrgb, const std::string &matname)
{
if (!mesh.textures[i])
{
Log::fatal("STKMesh", "Missing texture %d for material %s", i, matname.c_str());
return;
Log::error("STKMesh", "Missing texture %d for material %s", i, matname.c_str());
// use unicolor texture to replace missing texture
mesh.textures[i] = getUnicolorTexture(video::SColor(255, 127, 127, 127));
}
compressTexture(mesh.textures[i], isSrgb);
if (CVS->isAZDOEnabled())