From Mathias Froehlich, "Not so long time ago, there was a complaint about the ac3d plugin not honoring

absolute filenames for the texture images.

The attached change should fix this by at first looking at the absolute file
name to load a texture and then, if that fails, strip away any paths to try
that again with the bare file name.
The change also fixes a possible exception that could be triggered by an out
of bounds std::string access which is now avoided by using functions from
osgDB/FileUtils.

The change is based on rev 11161."
This commit is contained in:
Robert Osfield 2010-03-05 16:08:34 +00:00
parent 7db099a9d1
commit 8743e5d925

View File

@ -410,10 +410,25 @@ class FileData
TextureData toTextureData(const std::string& texName)
{
// If it is already there, use this
TextureDataMap::iterator i = mTextureStates.find(texName);
if (i == mTextureStates.end())
mTextureStates[texName].setTexture(texName, mOptions.get(), mModulateTexEnv.get());
return mTextureStates[texName];
if (i != mTextureStates.end())
return i->second;
// Try to load that texture.
TextureData textureData;
textureData.setTexture(texName, mOptions.get(), mModulateTexEnv.get());
if (textureData.valid()) {
mTextureStates[texName] = textureData;
return textureData;
}
// still no joy?, try with the stripped filename if this is different
// Try the pure file name if it is different
std::string simpleTexName = osgDB::getSimpleFileName(texName);
if (simpleTexName != texName)
return toTextureData(simpleTexName);
// Nothing that worked, return invalid data
return TextureData();
}
osg::Light* getNextLight()
@ -1160,20 +1175,7 @@ readObject(std::istream& stream, FileData& fileData, const osg::Matrix& parentTr
}
else if (token == "texture") {
// read the texture name
std::string texname = readString(stream);
// strip absolute paths
if (texname[0] == '/' ||
(isalpha(texname[0]) && texname[1] == ':')) {
std::string::size_type p = texname.rfind('\\');
if (p != std::string::npos)
texname = texname.substr(p+1, std::string::npos);
p = texname.rfind('/');
if (p != std::string::npos)
texname = texname.substr(p+1, std::string::npos);
}
textureData = fileData.toTextureData(texname);
textureData = fileData.toTextureData(readString(stream));
}
else if (token == "texrep") {
stream >> textureRepeat[0] >> textureRepeat[1];