- fixed memory leaks in map editor, g3dviewer and the game

This commit is contained in:
Mark Vejvoda
2012-07-21 20:21:27 +00:00
parent 8d168bdb4c
commit e1054d6e07
4 changed files with 34 additions and 3 deletions

View File

@@ -99,6 +99,8 @@ public:
* can be read or not depending on the file content*/
virtual bool canRead(ifstream& file) const;
virtual void cleanupExtensions();
/**Reads a file
* This method tries to read the file with the specified filepath
* If it fails, either <code>null</code> is returned or an exception
@@ -137,6 +139,7 @@ public:
virtual T* read(ifstream& file, const string& path, T* former) const = 0;
virtual ~FileReader() {
cleanupExtensions();
}; //Well ... these objects aren't supposed to be destroyed
};
@@ -283,6 +286,18 @@ FileReader<T>::FileReader(std::vector<string> extensions): extensions(extensions
}
}
template <typename T>
void FileReader<T>::cleanupExtensions() {
std::vector<string> nextExtension = extensions;
for(unsigned int i = 0; i < nextExtension.size(); ++i) {
vector<FileReader<T> const* >* curPossibleReaders = (getFileReadersMap())[nextExtension[i]];
if (curPossibleReaders != NULL) {
delete curPossibleReaders;
(getFileReadersMap())[nextExtension[i]] = NULL;
}
}
}
/**Gives a quick estimation of whether the specified file
* can be read or not depending on the filename*/
template <typename T>