• Advertisement
Sign in to follow this  

SFML - Window is just white and frozen

This topic is 840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement