Advertisement

SFML - Window is just white and frozen

Started by January 07, 2016 09:56 AM
3 comments, last by louie999 8 years, 11 months ago

So, when I was trying to make an GUI System for the game I'm making when I tried to test it the window shows up but was frozen and only white, then after a few seconds I will suddenly get a pop up window saying "Game.exe has stopped working" then it crashes. I don't know what I'm doing wrong, what could have possibly caused this? (I will post code if needed)

Too many potential issues. Code needed.

To look for the problem yourself, put breakpoints and step through your code, until you find the line/function that causes everything to hang.

Hello to all my stalkers.

Advertisement

I found it, it was in the main() function.


int main()
{ 
    std::cout << "Program begins...\n";
    std::string title = "Total War";
    std::cout << "Program begins...2\n";
    App* Main_Window = new App(title);
    std::cout << "Program begins...3\n";
    Gui::FontLoader fontLoader;
    std::cout << "Program begins...4\n";
    fontLoader.loadFont("FREESCPT.TTF");
    std::cout << "Program begins...5\n";
....

When I start the program the "Program begins...5" doesn't get printed, so I commented the "fontLoader.loadFont" function then my program worked without crashing, but I don't know why this happened, that line wasn't causing issues before, and I also haven't changed anything in that part of the code, but here's the code for that:


// header file
namespace Gui
{
    class FontLoader
    {
        public:
            sf::Font* font;

            FontLoader();
            bool loadFont(sf::String filepath);
    };
...
// .cpp file
Gui::FontLoader::FontLoader() {}

bool Gui::FontLoader::loadFont(sf::String filepath)
{
    if (!font->loadFromFile("Art/Fonts/" + filepath))
    {
        return false;
    }
    return true;
}

I haven't changed anything recently on that class/code, the only time that problem started to happen is when I made changes to my GUI system...

The most likely problem is that you aren't initialising the font member of the FontLoader class, and as it is a pointer to a sf::Font object it is most likely pointing to an invalid address when you call loadFont. The solution is to replace 'sf::Font*' with 'sf::Font' and the '->' with a '.', which will mean that the font member is always initialised when you construct a FontLoader.

The most likely problem is that you aren't initialising the font member of the FontLoader class, and as it is a pointer to a sf::Font object it is most likely pointing to an invalid address when you call loadFont. The solution is to replace 'sf::Font*' with 'sf::Font' and the '->' with a '.', which will mean that the font member is always initialised when you construct a FontLoader.

Thanks dude, I changed those and now it works without crashing :D

This topic is closed to new replies.

Advertisement