Report out-of-memory in some loading places

BTG can throw bad-alloc in the wild; catch this case and report it.
next
James Turner 4 years ago
parent b7234be625
commit 087547c6a0

@ -559,9 +559,16 @@ ModelRegistry::readImage(const string& fileName,
}
}
// REVIEW: Memory Leak - 262,144 bytes in 1 blocks are indirectly lost
// The leak occurs with OSG, but may be related to opt being a raw pointer
res = registry->readImageImplementation(absFileName, opt);
try {
// REVIEW: Memory Leak - 262,144 bytes in 1 blocks are indirectly lost
// The leak occurs with OSG, but may be related to opt being a raw pointer
res = registry->readImageImplementation(absFileName, opt);
} catch (std::bad_alloc&) {
simgear::reportFailure(simgear::LoadFailure::OutOfMemory, simgear::ErrorCode::ThreeDModelLoad,
"Out of memory loading texture", sg_location{absFileName});
return ReaderWriter::ReadResult::INSUFFICIENT_MEMORY_TO_LOAD;
}
if (!res.success()) {
SG_LOG(SG_IO, SG_DEV_WARN, "Image loading failed:" << res.message());
@ -733,7 +740,6 @@ ModelRegistry::readNode(const string& fileName,
ec.addFromMap(sgopt->getErrorContext());
}
ReaderWriter::ReadResult res;
CallbackMap::iterator iter
= nodeCallbackMap.find(getFileExtension(fileName));
ReaderWriter::ReadResult result;
@ -742,6 +748,11 @@ ModelRegistry::readNode(const string& fileName,
else
result = _defaultCallback->readNode(fileName, opt);
if (!result.validNode()) {
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::ThreeDModelLoad,
"Failed to load 3D model:" + result.message(), sg_location{fileName});
}
return result;
}

@ -73,8 +73,12 @@ SGReaderWriterBTG::readNode(const std::string& fileName,
"Failed to load BTG file:" + e.getFormattedMessage(),
e.getLocation());
return ReadResult::ERROR_IN_READING_FILE;
} catch (std::bad_alloc&) {
simgear::reportFailure(simgear::LoadFailure::OutOfMemory, simgear::ErrorCode::BTGLoad,
"Out of memory loading BTG:" + fileName, sg_location{fileName});
return ReadResult::ERROR_IN_READING_FILE;
}
return result;
}

Loading…
Cancel
Save