Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Strange memory error at program exit - help!!  (Read 2632 times)

0 Members and 1 Guest are viewing this topic.

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Strange memory error at program exit - help!!
« on: June 01, 2012, 02:07:20 pm »
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/UXAMR

As I said - if I dont destroy my Graphics singleton - everything is ok.. but obviously that will cause memory leaks :P

Anyone any idea?
« Last Edit: June 01, 2012, 02:57:53 pm by 1337matty »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange memory error at program exit - help!!
« Reply #1 on: June 01, 2012, 02:20:19 pm »
Can you please use the code=cpp tag instead of just code (it seems that removing it from the WYSIWYG editor and editing every incorrect post is still not enough for people to notice it...).

You should also show the complete definition of the GraphicsManager class.
Laurent Gomila - SFML developer

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Strange memory error at program exit - help!!
« Reply #2 on: June 01, 2012, 02:33:54 pm »
Sorry, I don't usually use forums :P

I have moved the graphics->release function to where graphics->getwindow().close happens and it seems to have fixed the problem
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange memory error at program exit - help!!
« Reply #3 on: June 01, 2012, 02:47:18 pm »
Quote
Sorry, I don't usually use forums
Ok but please edit your post :P

Quote
I have moved the graphics->release function to where graphics->getwindow().close happens and it seems to have fixed the problem
If you don't understand why it solves the problem, it might reappear someday.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Strange memory error at program exit - help!!
« Reply #4 on: June 01, 2012, 04:17:57 pm »
Can you please use the code=cpp tag instead of just code (it seems that removing it from the WYSIWYG editor and editing every incorrect post is still not enough for people to notice it...).
I was wondering where that button went xD
Couldn't you just let it print out code=cpp instead of only code?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange memory error at program exit - help!!
« Reply #5 on: June 01, 2012, 04:37:14 pm »
Quote
Couldn't you just let it print out code=cpp instead of only code?
Even better: there's a "code" dropdown list from which you can select the language, and which will print the correct "code=xxx" tag.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Strange memory error at program exit - help!!
« Reply #6 on: June 01, 2012, 04:48:34 pm »
Even better: there's a "code" dropdown list from which you can select the language, and which will print the correct "code=xxx" tag.
Oh I totally didn't see that, probably because it's on the same line as all the font stuff...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything