From 6a07c2282673562f67d12d31cd618be85d80f45a Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 7 Aug 2010 10:25:20 +0100 Subject: [PATCH] Catch subsystem update() exceptions in the manager, and permit a maximum number of exceptions before suspending the subsystem. --- simgear/structure/subsystem_mgr.cxx | 30 ++++++++++++++++++++++------- simgear/structure/subsystem_mgr.hxx | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index 26f026cd..9488faea 100644 --- a/simgear/structure/subsystem_mgr.cxx +++ b/simgear/structure/subsystem_mgr.cxx @@ -8,7 +8,7 @@ #include - +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(); + } } } diff --git a/simgear/structure/subsystem_mgr.hxx b/simgear/structure/subsystem_mgr.hxx index 02332056..5b449cca 100644 --- a/simgear/structure/subsystem_mgr.hxx +++ b/simgear/structure/subsystem_mgr.hxx @@ -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); -- 2.39.5