]> git.mxchange.org Git - flightgear.git/commitdiff
Fix segfault when loading routes in RouteManager
authorThorstenB <brehmt@gmail.com>
Wed, 7 Mar 2012 20:33:08 +0000 (21:33 +0100)
committerThorstenB <brehmt@gmail.com>
Wed, 7 Mar 2012 20:33:08 +0000 (21:33 +0100)
FGRouteMgr::loadRoute always needs to call "update_mirror" before
returning.

src/Autopilot/route_mgr.cxx

index abb266a9707007d428fe18bfd4f19dc37954561d..4abd9286f1fec2a99b32f4d6dcfdff2182eac8b7 100644 (file)
@@ -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)