]> git.mxchange.org Git - flightgear.git/commitdiff
Fix FGAIFlightPlan waypoint issues
authorThorstenB <brehmt@gmail.com>
Tue, 27 Nov 2012 20:02:32 +0000 (21:02 +0100)
committerThorstenB <brehmt@gmail.com>
Tue, 27 Nov 2012 20:02:32 +0000 (21:02 +0100)
Iterator must be reset after clearing waypoint list.
Deleting "*waypoint.end()" doesn't delete the last waypoint (end()-1
does - it is never actually used though).

src/AIModel/AIFlightPlan.cxx

index f2e5421d72fe77fa06693d0aa0790b1cb56f7777..5699a620c62bcf8520fa9bbb0f60d5ac928ef1dd 100644 (file)
@@ -286,21 +286,21 @@ FGAIWaypoint* const FGAIFlightPlan::getNextWaypoint( void ) const
 
 void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
 {
-  if (eraseWaypoints)
+    if (eraseWaypoints)
     {
-      if (wpt_iterator == waypoints.begin())
-       wpt_iterator++;
-      else
-       {
-         delete *(waypoints.begin());
-         waypoints.erase(waypoints.begin());
-         wpt_iterator = waypoints.begin();
-         wpt_iterator++;
-       }
+        if (wpt_iterator == waypoints.begin())
+            wpt_iterator++;
+        else
+        if (!waypoints.empty())
+        {
+            delete *(waypoints.begin());
+            waypoints.erase(waypoints.begin());
+            wpt_iterator = waypoints.begin();
+            wpt_iterator++;
+        }
     }
-  else
-    wpt_iterator++;
-
+    else
+        wpt_iterator++;
 }
 
 void FGAIFlightPlan::DecrementWaypoint(bool eraseWaypoints )
@@ -310,9 +310,10 @@ void FGAIFlightPlan::DecrementWaypoint(bool eraseWaypoints )
         if (wpt_iterator == waypoints.end())
             wpt_iterator--;
         else
+        if (!waypoints.empty())
         {
-            delete *(waypoints.end());
-            waypoints.erase(waypoints.end());
+            delete *(waypoints.end()-1);
+            waypoints.erase(waypoints.end()-1);
             wpt_iterator = waypoints.end();
             wpt_iterator--;
         }
@@ -397,6 +398,7 @@ void FGAIFlightPlan::deleteWaypoints()
   for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end();i++)
     delete (*i);
   waypoints.clear();
+  wpt_iterator = waypoints.begin();
 }
 
 // Delete all waypoints except the last,