Avoid segfault when a texture file is missing.

Always check the return value of "findDataFile". If it's empty, always
provide the _original_ path being searched in an error message. Otherwise
we eventually just get useless 'Can't find file "".' error messages
(and also a segfault here, since osgDB::readImageFile("") returns NULL).
This commit is contained in:
ThorstenB 2012-03-17 10:02:13 +01:00
parent 47c2dce26d
commit ca97e67511

View File

@ -213,8 +213,14 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
fullMaskPath = SGModelLib::findDataFile(ompath.str(), options); fullMaskPath = SGModelLib::findDataFile(ompath.str(), options);
} }
if (fullMaskPath.empty()) {
SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find texture file \""
<< ompath.str() << "\"");
}
else
{
osg::Image* image = osgDB::readImageFile(fullMaskPath, options); osg::Image* image = osgDB::readImageFile(fullMaskPath, options);
if (image->valid()) if (image && image->valid())
{ {
osg::Texture2D* object_mask = new osg::Texture2D; osg::Texture2D* object_mask = new osg::Texture2D;
@ -242,6 +248,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
} }
} }
} }
}
xsize = props->getDoubleValue("xsize", 0.0); xsize = props->getDoubleValue("xsize", 0.0);
ysize = props->getDoubleValue("ysize", 0.0); ysize = props->getDoubleValue("ysize", 0.0);