Hello All,
Been working on my game now for the past few days with no problems.
Recently, I have been getting a crash at the end of my program in VS2010 when I exit - this has only started happening recently.
if I comment out these lines in my graphics manager >
for (std::vector<sf::Texture*>::iterator deleter = mTextureList.begin(); deleter < mTextureList.end(); deleter++)
{
std::cout << "Deleting" << std::endl;
delete *deleter;
}
the error does not appear.. all this function does it clean up my graphics singleton and destroy all the textures I allocated when I did this function >
void GraphicsManager::CreateTexture(const char* filename)
{
sf::Texture* mTexture = new sf::Texture();
if(!mTexture->loadFromFile(filename))
std::cout << "Error loading texture: " + (char)filename << std::endl;
this->GetTextureList().push_back(mTexture);
}
I am releasing my Singleton and calling its destructor at the end of my main as follows;
#include <ctime>
#include "playstate.h"
#include "Logger.h"
#include "GraphicsManager.h"
#include "ProjectileManager.h"
#include <iostream>
int main()
{
#ifdef _DEBUG
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif
//Instance of Game Engine
GameEngine mGameEngine;
//Initialize the engine - set title, screen dimentions and boolean for fullscreen
mGameEngine.Init("Smash Them Zombies V1.0", 1280, 720, false);
//Load intro state - our entry to the game states.
mGameEngine.ChangeState(CPlayState::Instance());
Graphics->GetWindow().setFramerateLimit(60);
//Game Loop
while(Graphics->GetWindow().isOpen())
{
sf::Event event;
while (Graphics->GetWindow().pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
Graphics->GetWindow().close();
}
//Update game state events
mGameEngine.HandleEvents();
mGameEngine.Update();
mGameEngine.Draw();
}
Logfile->release();
ProjectilePool->release();
mGameEngine.Cleanup();
Graphics->release();
return EXIT_SUCCESS;
}
The error I get is below>
http://imgur.com/UXAMRAs I said - if I dont destroy my Graphics singleton - everything is ok.. but obviously that will cause memory leaks
Anyone any idea?