From: ThorstenB Date: Wed, 7 Mar 2012 20:33:08 +0000 (+0100) Subject: Fix segfault when loading routes in RouteManager X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bb59af4357395cb67c93bd0bae650b12d8a01c7e;p=flightgear.git Fix segfault when loading routes in RouteManager FGRouteMgr::loadRoute always needs to call "update_mirror" before returning. --- diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index abb266a97..4abd9286f 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -404,8 +404,8 @@ void FGRouteMgr::postinit() } SG_LOG(SG_AUTOPILOT, SG_INFO, "loaded initial waypoints:" << _route.size()); + update_mirror(); } - update_mirror(); weightOnWheels = fgGetNode("/gear/gear[0]/wow", true); // check airbone flag agrees with presets @@ -1345,28 +1345,37 @@ bool FGRouteMgr::loadRoute(const SGPath& path) SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str()); + bool Status = false; try { readProperties(path.str(), routeData); } catch (sg_exception& ) { // if XML parsing fails, the file might be simple textual list of waypoints - return loadPlainTextRoute(path); + Status = loadPlainTextRoute(path); + routeData = 0; } - - try { - int version = routeData->getIntValue("version", 1); - if (version == 1) { - loadVersion1XMLRoute(routeData); - } else if (version == 2) { - loadVersion2XMLRoute(routeData); - } else { - throw sg_io_exception("unsupported XML route version"); - } - return true; - } catch (sg_exception& e) { - SG_LOG(SG_IO, SG_ALERT, "Failed to load flight-plan '" << e.getOrigin() - << "'. " << e.getMessage()); - return false; + + if (routeData.valid()) + { + try { + int version = routeData->getIntValue("version", 1); + if (version == 1) { + loadVersion1XMLRoute(routeData); + } else if (version == 2) { + loadVersion2XMLRoute(routeData); + } else { + throw sg_io_exception("unsupported XML route version"); + } + Status = true; + } catch (sg_exception& e) { + SG_LOG(SG_IO, SG_ALERT, "Failed to load flight-plan '" << e.getOrigin() + << "'. " << e.getMessage()); + Status = false; + } } + + update_mirror(); + + return Status; } void FGRouteMgr::loadXMLRouteHeader(SGPropertyNode_ptr routeData)