mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 11:42:31 +01:00
- fixed memory leaks in map editor, g3dviewer and the game
This commit is contained in:
parent
8d168bdb4c
commit
e1054d6e07
@ -284,7 +284,8 @@ MainWindow::MainWindow( std::pair<string,vector<string> > unitToLoad,
|
||||
wxSize(Renderer::windowW, Renderer::windowH)),
|
||||
model(NULL), glCanvas(NULL), renderer(NULL),
|
||||
initTextureManager(true), timer(NULL),
|
||||
startupSettingsInited(false)
|
||||
startupSettingsInited(false),
|
||||
fileDialog(NULL)
|
||||
{
|
||||
this->appPath = appPath;
|
||||
Properties::setApplicationPath(executable_path(appPath));
|
||||
@ -531,6 +532,9 @@ MainWindow::~MainWindow(){
|
||||
delete timer;
|
||||
timer = NULL;
|
||||
|
||||
delete fileDialog;
|
||||
fileDialog = NULL;
|
||||
|
||||
delete model;
|
||||
model = NULL;
|
||||
|
||||
|
@ -113,6 +113,11 @@ Renderer::~Renderer() {
|
||||
//resources
|
||||
delete particleManager;
|
||||
delete modelManager;
|
||||
|
||||
if(GraphicsInterface::getInstance().getFactory() != NULL) {
|
||||
delete GraphicsInterface::getInstance().getFactory();
|
||||
GraphicsInterface::getInstance().setFactory(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
Renderer * Renderer::getInstance() {
|
||||
@ -174,8 +179,11 @@ Model * Renderer::getNewModel() {
|
||||
void Renderer::init() {
|
||||
assertGl();
|
||||
|
||||
GraphicsFactory *gf= new GraphicsFactoryGl();
|
||||
GraphicsInterface::getInstance().setFactory(gf);
|
||||
GraphicsFactory *gf= GraphicsInterface::getInstance().getFactory();
|
||||
if(gf == NULL) {
|
||||
gf= new GraphicsFactoryGl();
|
||||
GraphicsInterface::getInstance().setFactory(gf);
|
||||
}
|
||||
|
||||
modelRenderer= gf->newModelRenderer();
|
||||
textureManager= gf->newTextureManager();
|
||||
|
@ -80,6 +80,7 @@ MainWindow::MainWindow(string appPath)
|
||||
, menuBar(NULL)
|
||||
, panel(NULL)
|
||||
, glCanvas(NULL)
|
||||
, fileDialog(NULL)
|
||||
, program(NULL), boxsizer(NULL), startupSettingsInited(false) {
|
||||
|
||||
menuFile=NULL;
|
||||
@ -468,6 +469,9 @@ void MainWindow::setupStartupSettings() {
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete fileDialog;
|
||||
fileDialog = NULL;
|
||||
|
||||
delete program;
|
||||
program = NULL;
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user