Changed the index value to 0 of the token vector, wheras original the 1 was used, the

later causing a crash when only one token was available.  Also clean up #if #else #endif
block to help make the code more readable and maintainable.  This bug and fix
was found by Anders Backman, but final implementation done by Robert Osfield.
This commit is contained in:
Robert Osfield 2007-03-01 13:41:28 +00:00
parent c505e3d51e
commit 7c54b1b688

View File

@ -240,32 +240,15 @@ void Mesh::parseMeshMaterialList(ifstream& fin)
if (token.size() == 0)
continue;
// dgm - check for "{ <material name> }" for a
// check for "{ <material name> }" for a
// material which was declared globally
#if 1
Material * material = _obj->findMaterial(token[1]);
if (material) {
Material * material = _obj->findMaterial(token[0]);
if (material)
{
_materialList->material.push_back(*material);
continue;
}
#else
bool found = false;
if (token.size() > 2) {
std::vector<Material>::iterator itr;
for (itr = _globalMaterials.begin(); itr != _globalMaterials.end(); ++itr) {
if ( (*itr).name == token[1]) {
if (!_materialList)
_materialList = new MeshMaterialList;
_materialList->material.push_back(*itr);
found = true;
break;
}
}
}
if (found)
continue;
#endif
if (strrchr(buf, '}') != 0)
break;
else if (strrchr(buf, '{') != 0) {