]> git.mxchange.org Git - simgear.git/commitdiff
Catch subsystem update() exceptions in the manager, and permit a maximum number of...
authorJames Turner <zakalawe@mac.com>
Sat, 7 Aug 2010 09:25:20 +0000 (10:25 +0100)
committerJames Turner <zakalawe@mac.com>
Sat, 7 Aug 2010 09:25:20 +0000 (10:25 +0100)
simgear/structure/subsystem_mgr.cxx
simgear/structure/subsystem_mgr.hxx

index 26f026cd279976ecb49c876d70ced86ae0266610..9488faea51a06c1b2c58d624adc4f11f6a5c60c7 100644 (file)
@@ -8,7 +8,7 @@
 #include <simgear/math/SGMath.hxx>
 
 
-\f
+const int SG_MAX_SUBSYSTEM_EXCEPTIONS = 4;\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGSubsystem
 ////////////////////////////////////////////////////////////////////////
@@ -308,7 +308,8 @@ SGSubsystemGroup::Member::Member ()
       subsystem(0),
       min_step_sec(0),
       elapsed_sec(0),
-      collectTimeStats(false)
+      collectTimeStats(false),
+      exceptionCount(0)
 {
 }
 
@@ -326,11 +327,26 @@ void
 SGSubsystemGroup::Member::update (double delta_time_sec)
 {
     elapsed_sec += delta_time_sec;
-    if (elapsed_sec >= min_step_sec) {
-        if (!subsystem->is_suspended()) {
-            subsystem->update(elapsed_sec);
-            elapsed_sec = 0;
-        }
+    if (elapsed_sec < min_step_sec) {
+        return;
+    }
+    
+    if (subsystem->is_suspended()) {
+        return;
+    }
+    
+    try {
+      subsystem->update(elapsed_sec);
+      elapsed_sec = 0;
+    } catch (sg_exception& e) {
+      SG_LOG(SG_GENERAL, SG_ALERT, "caught exception processing subsystem:" << name
+        << "\nmessage:" << e.getMessage());
+      
+      if (++exceptionCount > SG_MAX_SUBSYSTEM_EXCEPTIONS) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "(exceptionCount=" << exceptionCount <<
+          ", suspending)");
+        subsystem->suspend();
+      }
     }
 }
 
index 02332056a7dbda213890486a71368adf8e7e2e74..5b449ccab160063b5539e8ae46cff2062d3f531c 100644 (file)
@@ -344,6 +344,7 @@ private:
         double min_step_sec;
         double elapsed_sec;
         bool collectTimeStats;
+        int exceptionCount;
     };
 
     Member * get_member (const string &name, bool create = false);