From 01da4616c7e9c920216624806f15943441004bbc Mon Sep 17 00:00:00 2001 From: "Jon S. Berndt" <34601451+jonsberndt@users.noreply.github.com> Date: Fri, 17 Dec 2021 11:32:57 -0700 Subject: [PATCH] Added error handling in FGWaypoint in case a supplied or calculated latitude exceeds 90 degrees prior (#536) --- 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 630cea511..5efdfb18b 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();