Effect builder: catch allocation failures
Fail on bad_alloc of reading texture images, instead of crashing.
This commit is contained in:
@@ -273,11 +273,19 @@ bool setAttrs(const TexTuple& attrs, Texture* tex,
|
|||||||
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS_NORMALIZED);
|
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS_NORMALIZED);
|
||||||
else
|
else
|
||||||
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
|
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
|
||||||
#if OSG_VERSION_LESS_THAN(3,4,2)
|
|
||||||
result = osgDB::readImageFile(imageName, options);
|
try {
|
||||||
#else
|
#if OSG_VERSION_LESS_THAN(3,4,2)
|
||||||
result = osgDB::readRefImageFile(imageName, options);
|
result = osgDB::readImageFile(imageName, options);
|
||||||
#endif
|
#else
|
||||||
|
result = osgDB::readRefImageFile(imageName, options);
|
||||||
|
#endif
|
||||||
|
} catch (std::bad_alloc& ba) {
|
||||||
|
SG_LOG(SG_GL, SG_ALERT, "Bad allocation loading:" << imageName);
|
||||||
|
// todo: report low memory warning
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
options->setLoadOriginHint(origLOH);
|
options->setLoadOriginHint(origLOH);
|
||||||
osg::ref_ptr<osg::Image> image;
|
osg::ref_ptr<osg::Image> image;
|
||||||
if (result.success())
|
if (result.success())
|
||||||
|
|||||||
Reference in New Issue
Block a user