]> git.mxchange.org Git - flightgear.git/commitdiff
Fix two sources of floating point exceptions
authortimoore <timoore>
Tue, 19 May 2009 22:14:04 +0000 (22:14 +0000)
committerTim Moore <timoore@redhat.com>
Tue, 2 Jun 2009 22:18:54 +0000 (00:18 +0200)
When a subsystem is updated, dt can be 0 if the program is paused. There
may be other subsystems that don't check that dt is non-zero.

src/Instrumentation/gps.cxx
src/Instrumentation/navradio.cxx

index 981c35af2e9978ab74eeb6f8c0b5ac7204745e28..2d448f575a94e833c409ce80247ef0c409c470bd 100644 (file)
@@ -479,9 +479,8 @@ GPS::updateTTWNode(UpdateContext& ctx, double distance_m, SGPropertyNode_ptr nod
     if (ctx.speed_kt > 0.0 && distance_m > 0.0) {
         TTW = (distance_m * SG_METER_TO_NM) / (ctx.speed_kt / 3600);
     }
-   
-    unsigned int TTW_seconds = (int) (TTW + 0.5);
-    if (TTW_seconds < 356400) { // That's 99 hours
+    if (TTW < 356400.5) { // That's 99 hours
+      unsigned int TTW_seconds = (int) (TTW + 0.5);
       unsigned int TTW_minutes = 0;
       unsigned int TTW_hours   = 0;
       char TTW_str[9];
index bb107b47d82364cb5196d296edd093b796ac2bb3..ceeefc8c599ab18ec53014d6edc70a9f2a8f3495 100644 (file)
@@ -593,16 +593,18 @@ FGNavRadio::update(double dt)
         // compute the time to intercept selected radial (based on
         // current and last cross track errors and dt
         //////////////////////////////////////////////////////////
-        double t = 0.0;
-        if ( inrange && cdi_serviceable ) {
-            double xrate_ms = (last_xtrack_error - xtrack_error) / dt;
-            if ( fabs(xrate_ms) > 0.00001 ) {
-                t = xtrack_error / xrate_ms;
-            } else {
-                t = 9999.9;
+        if (dt > 0) { // Are we paused?
+            double t = 0.0;
+            if ( inrange && cdi_serviceable ) {
+                double xrate_ms = (last_xtrack_error - xtrack_error) / dt;
+                if ( fabs(xrate_ms) > 0.00001 ) {
+                    t = xtrack_error / xrate_ms;
+                } else {
+                    t = 9999.9;
+                }
             }
+            time_to_intercept->setDoubleValue( t );
         }
-        time_to_intercept->setDoubleValue( t );
 
         //////////////////////////////////////////////////////////
         // compute the amount of glide slope needle deflection