From 8743e5d9251f3ffa91c906f4c5660a3bf072f99b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Mar 2010 16:08:34 +0000 Subject: [PATCH] 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." --- src/osgPlugins/ac/ac3d.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/osgPlugins/ac/ac3d.cpp b/src/osgPlugins/ac/ac3d.cpp index 747a87bee..b0e911b46 100644 --- a/src/osgPlugins/ac/ac3d.cpp +++ b/src/osgPlugins/ac/ac3d.cpp @@ -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];