From: curt Date: Wed, 5 Dec 2001 22:31:03 +0000 (+0000) Subject: In certain degenerate situations on the FlightGear side when the flight X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=74f10486bca01e26ef9aaa50da1f283b05340f45;p=simgear.git In certain degenerate situations on the FlightGear side when the flight model math blows up, the lat/lon could be nan. Thus updateLocal() could potentially called with nan arguments if FlightGear is reiniting from a blown up state. This is a bug in FlightGear, but I've added a simple check to catch this so updateLocal() is robust if called under these circumstances. --- diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index 76fb6f40..e1376e63 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -31,7 +31,6 @@ #include // for errno #ifdef SG_HAVE_STD_INCLUDES -# include # include # include # include @@ -39,7 +38,6 @@ # include # include # include -# include #endif #ifdef HAVE_SYS_TIMEB_H @@ -52,6 +50,8 @@ # include // for get/setitimer, gettimeofday, struct timeval #endif +#include // for NAN + #include #include #include @@ -259,6 +259,25 @@ void SGTime::update( double lon, double lat, long int warp ) { // Given lon/lat, update timezone information and local_offset void SGTime::updateLocal( double lon, double lat, const string& root ) { + // sanity checking + if ( lon < SGD_PI || lon > SGD_PI ) { + // not within -180 ... 180 + lon = 0.0; + } + if ( lat < SGD_PI * 0.5 || lat > SGD_PI * 0.5 ) { + // not within -90 ... 90 + lat = 0.0; + } + if ( lon != lon ) { + // only true if lon == nan + SG_LOG( SG_EVENT, SG_ALERT, " Detected lon == nan, resetting to 0.0" ); + lon = 0.0; + } + if ( lat != lat ) { + // only true if lat == nan + SG_LOG( SG_EVENT, SG_ALERT, " Detected lat == nan, resetting to 0.0" ); + lat = 0.0; + } time_t currGMT; time_t aircraftLocalTime; GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );