From 0a7e6b9b84697ab0aa6109841cccc105aebd003a Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 23 Mar 2021 17:06:05 +0000 Subject: [PATCH] Subsystems: add checks to avoid crash on early exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t crash if the user exits before subsystems are bound / init-ed --- simgear/structure/subsystem_mgr.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index 283a1365..f4863adf 100644 --- a/simgear/structure/subsystem_mgr.cxx +++ b/simgear/structure/subsystem_mgr.cxx @@ -340,6 +340,11 @@ SGSubsystemGroup::reinit () void SGSubsystemGroup::shutdown () { + if (_state < State::INIT) { + SG_LOG(SG_EVENT, SG_ALERT, "Shutdown of non-init-ed group:" << _name); + return; + } + reverseForEach([this](SGSubsystem* s){ this->notifyWillChange(s, State::SHUTDOWN); s->shutdown(); @@ -363,6 +368,11 @@ SGSubsystemGroup::bind () void SGSubsystemGroup::unbind () { + if (_state < State::BIND) { + SG_LOG(SG_EVENT, SG_ALERT, "Unbind of non-bound group:" << _name); + return; + } + reverseForEach([this](SGSubsystem* s){ this->notifyWillChange(s, State::UNBIND); s->unbind();