From: mfranz Date: Thu, 6 Dec 2007 18:32:43 +0000 (+0000) Subject: - move exception handling from init() and childAdded() to add_model() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8380fb4463fee4260499960fd68fd076830c38a6;p=flightgear.git - move exception handling from init() and childAdded() to add_model() - tell why loading a model failed --- diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 29666e074..0ec617b0b 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -51,13 +51,8 @@ FGModelMgr::init () { vector model_nodes = _models->getChildren("model"); - for (unsigned int i = 0; i < model_nodes.size(); i++) { - try { + for (unsigned int i = 0; i < model_nodes.size(); i++) add_model(model_nodes[i]); - } catch (const sg_throwable& t) { - SG_LOG(SG_GENERAL, SG_ALERT, t.getFormattedMessage() << t.getOrigin()); - } - } } void @@ -70,12 +65,21 @@ FGModelMgr::add_model (SGPropertyNode * node) instance->model = model; instance->node = node; SGModelLib *model_lib = globals->get_model_lib(); - osg::Node *object = model_lib->load_model( - globals->get_fg_root(), - node->getStringValue("path", - "Models/Geometry/glider.ac"), - globals->get_props(), - globals->get_sim_time_sec(), /*cache_object=*/false); + + const char *path = node->getStringValue("path", "Models/Geometry/glider.ac"); + osg::Node *object; + + try { + object = model_lib->load_model( + globals->get_fg_root(), + path, + globals->get_props(), + globals->get_sim_time_sec(), /*cache_object=*/false); + } catch (const sg_throwable& t) { + SG_LOG(SG_GENERAL, SG_ALERT, "Error loading " << path << ":\n " + << t.getFormattedMessage() << t.getOrigin()); + return; + } model->init( object ); @@ -224,11 +228,7 @@ FGModelMgr::Listener::childAdded(SGPropertyNode * parent, SGPropertyNode * child if (strcmp(parent->getName(), "model") || strcmp(child->getName(), "load")) return; - try { - _mgr->add_model(parent); - } catch (const sg_throwable& t) { - SG_LOG(SG_GENERAL, SG_ALERT, t.getFormattedMessage() << t.getOrigin()); - } + _mgr->add_model(parent); } void