Changeset 11175

Show
Ignore:
Timestamp:
03/05/10 17:08:34 (4 years ago)
Author:
robert
Message:

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."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/ac/ac3d.cpp

    r10758 r11175  
    411411    TextureData toTextureData(const std::string& texName) 
    412412    { 
     413        // If it is already there, use this 
    413414        TextureDataMap::iterator i = mTextureStates.find(texName); 
    414         if (i == mTextureStates.end()) 
    415             mTextureStates[texName].setTexture(texName, mOptions.get(), mModulateTexEnv.get()); 
    416         return mTextureStates[texName]; 
     415        if (i != mTextureStates.end()) 
     416            return i->second; 
     417        // Try to load that texture. 
     418        TextureData textureData; 
     419        textureData.setTexture(texName, mOptions.get(), mModulateTexEnv.get()); 
     420        if (textureData.valid()) { 
     421            mTextureStates[texName] = textureData; 
     422            return textureData; 
     423        } 
     424        // still no joy?, try with the stripped filename if this is different 
     425        // Try the pure file name if it is different 
     426        std::string simpleTexName = osgDB::getSimpleFileName(texName); 
     427        if (simpleTexName != texName) 
     428            return toTextureData(simpleTexName); 
     429 
     430        // Nothing that worked, return invalid data 
     431        return TextureData(); 
    417432    } 
    418433 
     
    11611176        else if (token == "texture") { 
    11621177            // read the texture name 
    1163             std::string texname = readString(stream); 
    1164  
    1165             // strip absolute paths 
    1166             if (texname[0] == '/' ||  
    1167                 (isalpha(texname[0]) && texname[1] == ':')) { 
    1168                 std::string::size_type p = texname.rfind('\\'); 
    1169                 if (p != std::string::npos) 
    1170                     texname = texname.substr(p+1, std::string::npos); 
    1171                 p = texname.rfind('/'); 
    1172                 if (p != std::string::npos) 
    1173                     texname = texname.substr(p+1, std::string::npos); 
    1174             } 
    1175          
    1176             textureData = fileData.toTextureData(texname); 
     1178            textureData = fileData.toTextureData(readString(stream)); 
    11771179        } 
    11781180        else if (token == "texrep") {