- 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)),
|
wxSize(Renderer::windowW, Renderer::windowH)),
|
||||||
model(NULL), glCanvas(NULL), renderer(NULL),
|
model(NULL), glCanvas(NULL), renderer(NULL),
|
||||||
initTextureManager(true), timer(NULL),
|
initTextureManager(true), timer(NULL),
|
||||||
startupSettingsInited(false)
|
startupSettingsInited(false),
|
||||||
|
fileDialog(NULL)
|
||||||
{
|
{
|
||||||
this->appPath = appPath;
|
this->appPath = appPath;
|
||||||
Properties::setApplicationPath(executable_path(appPath));
|
Properties::setApplicationPath(executable_path(appPath));
|
||||||
|
@ -531,6 +532,9 @@ MainWindow::~MainWindow(){
|
||||||
delete timer;
|
delete timer;
|
||||||
timer = NULL;
|
timer = NULL;
|
||||||
|
|
||||||
|
delete fileDialog;
|
||||||
|
fileDialog = NULL;
|
||||||
|
|
||||||
delete model;
|
delete model;
|
||||||
model = NULL;
|
model = NULL;
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,11 @@ Renderer::~Renderer() {
|
||||||
//resources
|
//resources
|
||||||
delete particleManager;
|
delete particleManager;
|
||||||
delete modelManager;
|
delete modelManager;
|
||||||
|
|
||||||
|
if(GraphicsInterface::getInstance().getFactory() != NULL) {
|
||||||
|
delete GraphicsInterface::getInstance().getFactory();
|
||||||
|
GraphicsInterface::getInstance().setFactory(NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer * Renderer::getInstance() {
|
Renderer * Renderer::getInstance() {
|
||||||
|
@ -174,8 +179,11 @@ Model * Renderer::getNewModel() {
|
||||||
void Renderer::init() {
|
void Renderer::init() {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
GraphicsFactory *gf= new GraphicsFactoryGl();
|
GraphicsFactory *gf= GraphicsInterface::getInstance().getFactory();
|
||||||
GraphicsInterface::getInstance().setFactory(gf);
|
if(gf == NULL) {
|
||||||
|
gf= new GraphicsFactoryGl();
|
||||||
|
GraphicsInterface::getInstance().setFactory(gf);
|
||||||
|
}
|
||||||
|
|
||||||
modelRenderer= gf->newModelRenderer();
|
modelRenderer= gf->newModelRenderer();
|
||||||
textureManager= gf->newTextureManager();
|
textureManager= gf->newTextureManager();
|
||||||
|
|
|
@ -80,6 +80,7 @@ MainWindow::MainWindow(string appPath)
|
||||||
, menuBar(NULL)
|
, menuBar(NULL)
|
||||||
, panel(NULL)
|
, panel(NULL)
|
||||||
, glCanvas(NULL)
|
, glCanvas(NULL)
|
||||||
|
, fileDialog(NULL)
|
||||||
, program(NULL), boxsizer(NULL), startupSettingsInited(false) {
|
, program(NULL), boxsizer(NULL), startupSettingsInited(false) {
|
||||||
|
|
||||||
menuFile=NULL;
|
menuFile=NULL;
|
||||||
|
@ -468,6 +469,9 @@ void MainWindow::setupStartupSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
delete fileDialog;
|
||||||
|
fileDialog = NULL;
|
||||||
|
|
||||||
delete program;
|
delete program;
|
||||||
program = NULL;
|
program = NULL;
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,8 @@ public:
|
||||||
* can be read or not depending on the file content*/
|
* can be read or not depending on the file content*/
|
||||||
virtual bool canRead(ifstream& file) const;
|
virtual bool canRead(ifstream& file) const;
|
||||||
|
|
||||||
|
virtual void cleanupExtensions();
|
||||||
|
|
||||||
/**Reads a file
|
/**Reads a file
|
||||||
* This method tries to read the file with the specified filepath
|
* This method tries to read the file with the specified filepath
|
||||||
* If it fails, either <code>null</code> is returned or an exception
|
* 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 T* read(ifstream& file, const string& path, T* former) const = 0;
|
||||||
|
|
||||||
virtual ~FileReader() {
|
virtual ~FileReader() {
|
||||||
|
cleanupExtensions();
|
||||||
}; //Well ... these objects aren't supposed to be destroyed
|
}; //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
|
/**Gives a quick estimation of whether the specified file
|
||||||
* can be read or not depending on the filename*/
|
* can be read or not depending on the filename*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Reference in New Issue