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

Author Topic: Issues with loadFromFiles() Methods.  (Read 1231 times)

0 Members and 1 Guest are viewing this topic.

Janacek

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Issues with loadFromFiles() Methods.
« on: October 16, 2013, 11:28:31 pm »
Hi,

I'm having issues in a project using sfml 2.1.

I've made a clone of pacman. The game is working fine and all, but I always played it using Visual Studio 2012.

Some hours ago I tried to launch it using the binary, what was my surprise when I saw an error.

"Pacman has stopped working"...

I've fixed some bugs on some STL containers but now the game crashes randomly during the construction of my main class.
Sometimes it also generates everything and the game launches.

I really don't understand where the bug is from, maybe an heap corruption ?

        msvcr110.dll!malloc(unsigned int size) Ligne 91 C
        msvcr110.dll!operator new(unsigned int size) Ligne 59   C++

here is a part of the call stack, it shows a call to new then to malloc. I actually don't do any new in the constructor except for an sf::Texture, so I assume it's the calls into loadFromFile()... ? And even so, I made a project yesterday using the same functions in the SFML and I didn't get errors.

What could raise those errors ?

I'm also using windows 8.1 RTM, I don't think the SFML has issues with it :o

        this->_tileset.loadFromFile("./pacman_sprites.png");



        this->_font.loadFromFile("./font.ttf");

        this->_highScoreText.setFont(this->_font);
        this->_highScoreText.setString("HIGHSCORE");
        this->_highScoreText.setCharacterSize(16);
        this->_highScoreText.setColor(sf::Color::White);
        this->_highScoreText.setPosition(72, -8);

        this->_score.setFont(this->_font);
        this->_score.setString("0");
        this->_score.setCharacterSize(16);
        this->_score.setColor(sf::Color::White);
        this->_score.setPosition(56, 0);

        this->_start.setFont(this->_font);
        this->_start.setString("GET READY");
        this->_start.setCharacterSize(32);
        this->_start.setColor(sf::Color::White);
        int tmpStart = this->_win.getSize().x - this->_start.getGlobalBounds().width;
        this->_start.setPosition(tmpStart / 2, this->_win.getSize().y / 2 - this->_start.getGlobalBounds().height);

        sf::Texture *tmp = new sf::Texture();
        tmp->loadFromFile("./pacman_animations.png");
        this->_pacman.setPos(std::pair<float, float>(102, 180));
        this->_pacman.init(tmp);

That's the code written in the constructor, I don't see any weird settings. I've also made sure all the dependencies are in the good folders.

Do someone ever had this king of issues ?

Thanks !

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Issues with loadFromFiles() Methods.
« Reply #1 on: October 16, 2013, 11:41:42 pm »
Try compiling with all warnings turned on so you can fix any uninitialized variables and other easy stuff.

Then use your debugger to figure out exactly where it's crashing.  Do not ever guess where a crash is happening; find out for sure.

If that doesn't cut it, you'll have to reduce your code to a complete and minimal example that reproduces the problem in order for us to help.

P.S. Every single time we ask people to post complete and minimal code, they always post one or the other and not both.  Please do both so we can actually help.