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

Author Topic: [C++] Setting font crashes app / doesn't display.  (Read 1501 times)

0 Members and 1 Guest are viewing this topic.

Rietty

  • Newbie
  • *
  • Posts: 5
    • View Profile
[C++] Setting font crashes app / doesn't display.
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: [C++] Setting font crashes app / doesn't display.
« Reply #1 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.
« Last Edit: May 10, 2018, 07:18:01 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Rietty

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: [C++] Setting font crashes app / doesn't display.
« Reply #2 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.

 

anything