From c25035e264990fcff99dca2c165801028840b89f Mon Sep 17 00:00:00 2001 From: Jon Berndt Date: Fri, 10 Dec 2021 13:20:47 -0700 Subject: [PATCH] Added error handling in FGWaypoint in case a supplied or calculated latitude exceeds 90 degrees prior --- src/models/flight_control/FGWaypoint.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/models/flight_control/FGWaypoint.cpp b/src/models/flight_control/FGWaypoint.cpp index 630cea5119..5efdfb18ba 100644 --- a/src/models/flight_control/FGWaypoint.cpp +++ b/src/models/flight_control/FGWaypoint.cpp @@ -178,7 +178,24 @@ bool FGWaypoint::Run(void ) double target_longitude_rad = target_longitude->GetValue() * target_longitude_unit; source.SetPositionGeodetic(source_longitude_rad, source_latitude_rad, 0.0); + if (fabs(target_latitude_rad) > M_PI/2.0) { + cerr << endl; + cerr << "Target latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl; + cerr << "(is longitude being mistakenly supplied?)" << endl; + cerr << endl; + throw("Waypoint target latitude exceeded 90 degrees."); + } + + if (fabs(source_latitude_rad) > M_PI/2.0) { + cerr << endl; + cerr << "Source latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl; + cerr << "(is longitude being mistakenly supplied?)" << endl; + cerr << endl; + throw("Source latitude exceeded 90 degrees."); + } + if (WaypointType == eHeading) { // Calculate Heading + double heading_to_waypoint_rad = source.GetHeadingTo(target_longitude_rad, target_latitude_rad); @@ -186,11 +203,12 @@ bool FGWaypoint::Run(void ) else Output = heading_to_waypoint_rad; } else { // Calculate Distance + double wp_distance = source.GetDistanceTo(target_longitude_rad, target_latitude_rad); - if (eUnit == eMeters) Output = FeetToMeters(wp_distance); else Output = wp_distance; + } Clip();