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.
This commit is contained in:
parent
2b12425a62
commit
74f10486bc
@ -31,7 +31,6 @@
|
|||||||
#include <errno.h> // for errno
|
#include <errno.h> // for errno
|
||||||
|
|
||||||
#ifdef SG_HAVE_STD_INCLUDES
|
#ifdef SG_HAVE_STD_INCLUDES
|
||||||
# include <cmath>
|
|
||||||
# include <cstdio>
|
# include <cstdio>
|
||||||
# include <cstdlib>
|
# include <cstdlib>
|
||||||
# include <ctime>
|
# include <ctime>
|
||||||
@ -39,7 +38,6 @@
|
|||||||
# include <math.h>
|
# include <math.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <time.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SYS_TIMEB_H
|
#ifdef HAVE_SYS_TIMEB_H
|
||||||
@ -52,6 +50,8 @@
|
|||||||
# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
|
# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <math.h> // for NAN
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
@ -259,6 +259,25 @@ void SGTime::update( double lon, double lat, long int warp ) {
|
|||||||
|
|
||||||
// Given lon/lat, update timezone information and local_offset
|
// Given lon/lat, update timezone information and local_offset
|
||||||
void SGTime::updateLocal( double lon, double lat, const string& root ) {
|
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 currGMT;
|
||||||
time_t aircraftLocalTime;
|
time_t aircraftLocalTime;
|
||||||
GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
|
GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
|
||||||
|
Loading…
Reference in New Issue
Block a user