From 069483e6d03953655b2103867e42e201a8cb83cd Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 23 Jun 2021 13:26:40 +0100 Subject: [PATCH] Add try/catch wrappers in SGSubsystemGroup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attempt to narrow down the source of some fatal exceptions we see on Senty, which occur during init/startup. All these blocks re-throw so user behaviour is unchanged, but we’ll log the name of the subsytem. --- simgear/structure/subsystem_mgr.cxx | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index f4863adf..0249ccd6 100644 --- a/simgear/structure/subsystem_mgr.cxx +++ b/simgear/structure/subsystem_mgr.cxx @@ -251,10 +251,15 @@ void SGSubsystemGroup::init () { assert(_state == State::BIND); - forEach([this](SGSubsystem* s){ - this->notifyWillChange(s, State::INIT); - s->init(); - this->notifyDidChange(s, State::INIT); + forEach([this](SGSubsystem* s) { + try { + this->notifyWillChange(s, State::INIT); + s->init(); + this->notifyDidChange(s, State::INIT); + } catch (std::exception& e) { + simgear::reportError("Caught exception init-ing subsystem " + s->subsystemId() + "\n\t" + e.what()); + throw; + } }); _state = State::INIT; } @@ -284,7 +289,15 @@ SGSubsystemGroup::incrementalInit() const auto m = _members[_initPosition]; SGTimeStamp st; st.stamp(); - const InitStatus memberStatus = m->subsystem->incrementalInit(); + InitStatus memberStatus; + + try { + memberStatus = m->subsystem->incrementalInit(); + } catch (std::exception& e) { + simgear::reportError("Caught exception init-ing subsystem " + m->subsystem->subsystemId() + "\n\t" + e.what()); + throw; + } + m->initTime += st.elapsedMSec(); if (memberStatus == INIT_DONE) { @@ -357,10 +370,15 @@ SGSubsystemGroup::shutdown () void SGSubsystemGroup::bind () { - forEach([this](SGSubsystem* s){ - this->notifyWillChange(s, State::BIND); - s->bind(); - this->notifyDidChange(s, State::BIND); + forEach([this](SGSubsystem* s) { + try { + this->notifyWillChange(s, State::BIND); + s->bind(); + this->notifyDidChange(s, State::BIND); + } catch (std::exception& e) { + simgear::reportError("Caught exception binding subsystem " + s->subsystemId() + "\n\t" + e.what()); + throw; + } }); _state = State::BIND; }