Modules now properly remove themselves from the global registry when they're deleted

This commit is contained in:
Alex Szpakowski
2013-08-30 23:40:46 -03:00
parent d3826aba9d
commit a3571b97bd
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -35,6 +35,21 @@ namespace
namespace love
{
Module::~Module()
{
std::map<std::string, Module*>::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<std::string, Module*>::iterator it = registry.find(name);
if (registry.end() != it)
if (it != registry.end())
{
if (it->second == instance)
return;
+1 -1
View File
@@ -38,7 +38,7 @@ public:
/**
* Destructor.
**/
virtual ~Module() {};
virtual ~Module();
/**
* Gets the name of the module. This is used in case of errors