From b36f19b8714dcb82b80f7bb3c3fb1681a3ab02b3 Mon Sep 17 00:00:00 2001
From: curt <curt>
Date: Fri, 19 Apr 2002 14:05:58 +0000
Subject: [PATCH] Detect and recover from a math overflow that can possibly
 prevent panel text from updating if the instrument panel is not drawn for
 more then 35.7 minutes.

---
 src/Cockpit/panel.cxx | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx
index f04ec8f73..6e78219c8 100644
--- a/src/Cockpit/panel.cxx
+++ b/src/Cockpit/panel.cxx
@@ -1012,7 +1012,29 @@ FGTextLayer::draw ()
     text_renderer.start3f(0, 0, 0);
 
     _now.stamp();
-    if (_now - _then > 100000) {
+    long diff = _now - _then;
+#if 0
+    // It would be nice to keep this #ifdef'd stuff for (04/18/2002 +
+    // a couple days) as I verify my solution to the panel text
+    // drawing problem is actually correct. -CLO
+    cout << "time diff = " << diff << endl;
+    if ( _now - _then < 0 ) {
+        cout << "Eeek, the past is now in the future!" << endl;
+        cout << "Now = " << _now.get_seconds() << " seconds "
+             << _now.get_usec() << "usecs" << endl;
+        cout << "Past = " << _then.get_seconds() << " seconds "
+             << _then.get_usec() << "usecs" << endl;
+        exit(-1);
+    }
+#endif
+    if (diff > 100000 || diff < 0 ) {
+      // ( diff < 0 ) is a sanity check and indicates our time stamp
+      // difference math probably overflowed.  We can handle a max
+      // difference of 35.8 minutes since the returned value is in
+      // usec.  So if the panel is left off longer than that we can
+      // over flow the math with it is turned back on.  This (diff <
+      // 0) catches that situation, get's us out of trouble, and
+      // back on track.
       recalc_value();
       _then = _now;
     }