Crash prevention: throw during dtor

get_manager() will be called during dtor, so throwing an exception would cause a hard crash.
This commit is contained in:
Scott Giese 2020-12-17 17:02:40 -06:00
parent 9bac911fe1
commit e031ea7f7c

View File

@ -175,9 +175,10 @@ SGSubsystemGroup* SGSubsystem::get_group() const
SGSubsystemMgr* SGSubsystem::get_manager() const
{
if (!get_group())
throw sg_exception("SGSubsystem::get_manager: subsystem " + subsystemId() + " has no group");
return get_group()->get_manager();
if (auto group = get_group(); group)
return group->get_manager();
return nullptr;
}
std::string SGSubsystem::nameForState(State s)
@ -695,8 +696,7 @@ SGSubsystemGroup::remove_subsystem(const string &name)
void
SGSubsystemGroup::notifyWillChange(SGSubsystem* sub, SGSubsystemMgr::State s)
{
auto manager = get_manager();
if (manager) {
if (auto manager = get_manager(); manager) {
manager->notifyDelegatesWillChange(sub, s);
}
}
@ -704,8 +704,7 @@ SGSubsystemGroup::notifyWillChange(SGSubsystem* sub, SGSubsystemMgr::State s)
void
SGSubsystemGroup::notifyDidChange(SGSubsystem* sub, SGSubsystemMgr::State s)
{
auto manager = get_manager();
if (manager) {
if (auto manager = get_manager(); manager) {
manager->notifyDelegatesDidChange(sub, s);
}
}
@ -761,8 +760,7 @@ auto SGSubsystemGroup::get_member(const string &name, bool create) -> Member*
SGSubsystemMgr* SGSubsystemGroup::get_manager() const
{
auto parentGroup = get_group();
if (parentGroup) {
if (auto parentGroup = get_group(); parentGroup) {
return parentGroup->get_manager();
}