SFML community forums

Help => General => Topic started by: Rietty on May 10, 2018, 04:27:49 am

Title: [C++] Setting font crashes app / doesn't display.
Post by: Rietty on May 10, 2018, 04:27:49 am
Hi! So I have this code:



// SFML Headers.
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Image.hpp>
#include <fstream>


int main() {
    // Create the main window
    sf::RenderWindow *window = new sf::RenderWindow(sf::VideoMode(800, 600), "Window");
    sf::Font font; // Needed.
    if (!font.loadFromFile("font.ttf")){
        std::ofstream out("log.txt");
        out << "Failed to load font from file!" << std::endl;
        out.close();
    }
    // Loads it from file and sets it.
    while (window->isOpen()) {
        // Process events.
        sf::Event event;
        while (window->pollEvent(event)) {  
            // Close window: Exit.
            if (event.type == sf::Event::Closed) {
                window->close();
            }
        }
        // Clear screen.
        window->clear();
        sf::Text text;
        text.setFont(font);
        text.setString("Hello, Menu!");
        text.setCharacterSize(24);
        text.setFillColor(sf::Color::White);
        text.setStyle(sf::Text::Bold | sf::Text::Underlined);
        // Update the window.
        window->display();
    }
    return EXIT_SUCCESS;
}
 


For some reason this never displays anything in my window, which is just black box with no text at all. And in my main application (this is a minimal example.) it crashes on this line:



text.setFont(font);
 


I'm not sure why nothing displays? I followed tutorial to the word.
Title: Re: [C++] Setting font crashes app / doesn't display.
Post by: eXpl0it3r on May 10, 2018, 06:49:48 am
I saw your callstack on Discord.

You're using a MinGW x64 compiler with SJLJ exception model, yet the binaries we provide uses the SEH exception model for x64 MinGW.

Either switch your compiler or build from source.
Title: Re: [C++] Setting font crashes app / doesn't display.
Post by: Rietty on May 10, 2018, 03:48:36 pm
I saw your callstack on Discord.

You're using a MinGW x64 compiler with SJLJ exception model, yet the binaries we provide uses the SEH exception model for x64 MinGW.

Either switch your compiler or build from source.

This is built from source however.