]> git.mxchange.org Git - flightgear.git/commitdiff
KLN89: Fix both incorrect behaviour and a segfault when deleting a partially-entered...
authorDave Luff <daveluff@ntlworld.com>
Tue, 23 Nov 2010 10:51:37 +0000 (10:51 +0000)
committerDave Luff <daveluff@ntlworld.com>
Tue, 23 Nov 2010 10:51:37 +0000 (10:51 +0000)
src/Instrumentation/KLN89/kln89_page_fpl.cxx

index 8497ece124073b2d116df6f8a743cc51d9c09606..289e7c509dae69ff677f1d1d2a989f9343f601bb 100644 (file)
@@ -600,8 +600,25 @@ void KLN89FplPage::ClrPressed() {
             // TODO - see if we need to delete a waypoint
             if(_uLinePos >= 4) {
                 if(_delWp) {
+                    // If we are already displaying a clear waypoint dialog in response to the CLR button,
+                    // then a further press of the CLR button cancels the dialog.
                     _kln89->_mode = KLN89_MODE_DISP;
                     _delWp = false;
+                } else if(_bEntWp) {
+                    // If we are currently entering a waypoint, then CLR deletes it unconditionally
+                    // without a confirmation dialog and cancels waypoint entry.
+                    int pos = _uLinePos - 4 + _fplPos;
+                    // Sanity check - the calculated wp position should never be off the end of the waypoint list.
+                    if(pos > static_cast<int>(_kln89->_flightPlans[_subPage]->waypoints.size()) - 1) {
+                        SG_LOG(SG_GENERAL, SG_ALERT, "ERROR - _uLinePos too big in KLN89FplPage::ClrPressed!\n");
+                        return;
+                    }
+                    _kln89->_flightPlans[_subPage]->waypoints.erase(_kln89->_flightPlans[_subPage]->waypoints.begin() + pos);
+                    _bEntWp = false;
+                    _entWp = NULL;
+                    _entWpStr.clear();
+                    _wLinePos = 0;
+                    // Do we need to re-calc _fplPos here?                    
                 } else {
                     // First check that we're not trying to delete an approach waypoint.  Note that we can delete the approach by deleting the header though.
                     // Check for approach waypoints or header/fences in flightplan 0
@@ -685,7 +702,7 @@ void KLN89FplPage::EntPressed() {
         int pos = _uLinePos - 4 + _fplPos;
         // Sanity check - the calculated wp position should never be off the end of the waypoint list.
         if(pos > static_cast<int>(_kln89->_flightPlans[_subPage]->waypoints.size()) - 1) {
-            cout << "ERROR - _uLinePos too big in KLN89FplPage::EntPressed!\n";
+            SG_LOG(SG_GENERAL, SG_ALERT, "ERROR - _uLinePos too big in KLN89FplPage::EntPressed!\n");
             return;
         }
         _kln89->_flightPlans[_subPage]->waypoints.erase(_kln89->_flightPlans[_subPage]->waypoints.begin() + pos);
@@ -731,7 +748,7 @@ void KLN89FplPage::EntPressed() {
                 ((KLN89Page*)_kln89->_pages[4])->SetEntInvert(true);
                 break;
             default:
-                cout << "Error - unknown waypoint type found in KLN89::FplPage::EntPressed()\n";
+                SG_LOG(SG_GENERAL, SG_ALERT, "Error - unknown waypoint type found in KLN89::FplPage::EntPressed()\n");
             }
             _kln89->_activePage->SetId(_entWp->id);
             _kln89->_entJump = 7;