From a3571b97bd38f63fa4f19a112facd372bcbb15a6 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 30 Aug 2013 23:40:46 -0300 Subject: [PATCH] Modules now properly remove themselves from the global registry when they're deleted --- src/common/Module.cpp | 17 ++++++++++++++++- src/common/Module.h | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/Module.cpp b/src/common/Module.cpp index e464b4e0b..77fb30d86 100644 --- a/src/common/Module.cpp +++ b/src/common/Module.cpp @@ -35,6 +35,21 @@ namespace namespace love { +Module::~Module() +{ + std::map::iterator it; + + // We can't use the overridden Module::getName() in this destructor. + for (it = registry.begin(); it != registry.end(); ++it) + { + if (it->second == this) + { + registry.erase(it); + break; + } + } +} + void Module::registerInstance(Module *instance) { if (instance == NULL) @@ -44,7 +59,7 @@ void Module::registerInstance(Module *instance) std::map::iterator it = registry.find(name); - if (registry.end() != it) + if (it != registry.end()) { if (it->second == instance) return; diff --git a/src/common/Module.h b/src/common/Module.h index 4b5e70c52..e317b4f96 100644 --- a/src/common/Module.h +++ b/src/common/Module.h @@ -38,7 +38,7 @@ public: /** * Destructor. **/ - virtual ~Module() {}; + virtual ~Module(); /** * Gets the name of the module. This is used in case of errors