1
0
Fork 0

ModelMgr: catch not-found paths

When findDataFile reutrns an empty path, don't continue trying to pass
it to OSG.

SF-ID: https://sourceforge.net/p/flightgear/codetickets/2609/
This commit is contained in:
James Turner 2021-07-21 22:55:39 +01:00
parent 609eeb65e4
commit e64f70bc72

View file

@ -116,10 +116,12 @@ void FGModelMgr::shutdown()
void void
FGModelMgr::add_model (SGPropertyNode * node) FGModelMgr::add_model (SGPropertyNode * node)
{ {
SG_LOG(SG_AIRCRAFT, SG_INFO, const std::string model_path{node->getStringValue("path", "Models/Geometry/glider.ac")};
"Adding model " << node->getStringValue("name", "[unnamed]")); if (model_path.empty()) {
SG_LOG(SG_AIRCRAFT, SG_WARN, "add_model called with empty path");
const char *model_path = node->getStringValue("path", "Models/Geometry/glider.ac"); return;
}
osg::Node *object; osg::Node *object;
Instance * instance = new Instance; Instance * instance = new Instance;
@ -128,12 +130,19 @@ FGModelMgr::add_model (SGPropertyNode * node)
try { try {
std::string fullPath = simgear::SGModelLib::findDataFile(model_path); std::string fullPath = simgear::SGModelLib::findDataFile(model_path);
if (fullPath.empty()) {
SG_LOG(SG_AIRCRAFT, SG_ALERT, "add_model: unable to find model with name '" << model_path << "'");
return;
}
object = SGModelLib::loadDeferredModel(fullPath, globals->get_props()); object = SGModelLib::loadDeferredModel(fullPath, globals->get_props());
} catch (const sg_throwable& t) { } catch (const sg_throwable& t) {
SG_LOG(SG_AIRCRAFT, SG_ALERT, "Error loading " << model_path << ":\n " SG_LOG(SG_AIRCRAFT, SG_ALERT, "Error loading " << model_path << ":\n "
<< t.getFormattedMessage() << t.getOrigin()); << t.getFormattedMessage() << t.getOrigin());
return; return;
} }
const std::string modelName{node->getStringValue("name", model_path.c_str())};
SG_LOG(SG_AIRCRAFT, SG_INFO, "Adding model " << modelName);
SGModelPlacement *model = new SGModelPlacement; SGModelPlacement *model = new SGModelPlacement;
instance->model = model; instance->model = model;