Merge pull request #413 from michc/fix_waypoint_editor_bug

Fix for bug that throws array out of bounds error when editing the waypo...
This commit is contained in:
vshcherb 2013-02-26 16:07:31 -08:00
commit aec1e29da6

View file

@ -156,15 +156,22 @@ public class IntermediatePointsDialog {
} }
} }
if (cnt > 0) { if (cnt > 0) {
for (int i = checkedIntermediates.length - 1; i >= 0; i--) { boolean changeDestinationFlag =!checkedIntermediates [checkedIntermediates.length - 1];
if (!checkedIntermediates[i]) { if(cnt == checkedIntermediates.length){ //there is no alternative destination if all points are to be removed?
cnt--; app.getTargetPointsHelper().removeAllWayPoints((MapActivity) (mapActivity instanceof MapActivity?mapActivity : null), true);
app.getTargetPointsHelper().removeWayPoint((MapActivity) (mapActivity instanceof MapActivity?mapActivity : null), cnt == 0, }else{
i == checkedIntermediates.length - 1? -1 : i); for (int i = checkedIntermediates.length - 2; i >= 0; i--) { //skip the destination until a retained waypoint is found
if (checkedIntermediates[i] && changeDestinationFlag) { //Find a valid replacement for the destination
app.getTargetPointsHelper().makeWayPointDestination((MapActivity) (mapActivity instanceof MapActivity?mapActivity : null), cnt == 0, i);
changeDestinationFlag = false;
}else if(!checkedIntermediates[i]){
cnt--;
app.getTargetPointsHelper().removeWayPoint((MapActivity) (mapActivity instanceof MapActivity?mapActivity : null), cnt == 0, i);
}
}
if(mapActivity instanceof MapActivity) {
((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, "");
} }
}
if(mapActivity instanceof MapActivity) {
((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, "");
} }
} }
} }