Catch subsystem update() exceptions in the manager, and permit a maximum number of exceptions before suspending the subsystem.

This commit is contained in:
James Turner
2010-08-07 10:25:20 +01:00
parent 7c294915c8
commit 6a07c22826
2 changed files with 24 additions and 7 deletions

View File

@@ -8,7 +8,7 @@
#include <simgear/math/SGMath.hxx>
const int SG_MAX_SUBSYSTEM_EXCEPTIONS = 4;
////////////////////////////////////////////////////////////////////////
// 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();
}
}
}

View 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);