Commits

Alex Szpakowski committed c49b070

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

Comments (0)

Files changed (2)

src/common/Module.cpp

 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)
 
 	std::map<std::string, Module*>::iterator it = registry.find(name);
 
-	if (registry.end() != it)
+	if (it != registry.end())
 	{
 		if (it->second == instance)
 			return;

src/common/Module.h

 	/**
 	 * Destructor.
 	 **/
-	virtual ~Module() {};
+	virtual ~Module();
 
 	/**
 	 * Gets the name of the module. This is used in case of errors