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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - obscurelyme

Pages: [1]
1
Hello,

I'm looking for some advice on how to use sf::Text object. Specifically what is causing this crash to occur from Freetype library. Right now, any attempts to draw sf::Text results in a crash. I have included a link to my source code below as well as screenshots that showcase my setup after a build/crash. I am running 64-bit Windows with vcpkg as my main source of pulling in dependencies. I'm more than certain I am using debug libraries for a DEBUG build as vs code cmake tools sets by default.

My Source Code
https://github.com/obscurelyme/hello-sfml/blob/ed15963b38b896e414fab1b811ac5c8c7918e92d/main.cpp#L53-L73

Code Snippet:

// Load fonts
    std::string executableDirectory = std::filesystem::weakly_canonical(std::filesystem::path(argv[0])).parent_path().string();
    std::string relativeFontFile = "/assets/fonts/Roboto/Roboto-Regular.ttf";
    std::string fontFilePath = executableDirectory.append(relativeFontFile);
    sf::Font font;
    if (!font.loadFromFile(fontFilePath))
    {
        spdlog::debug("Could not load Roboto-Regular.ttf from directory {}", fontFilePath);
    }
    else
    {
        spdlog::debug("Successfully loaded {} font-family.", font.getInfo().family);
    }

    sf::Text text{"Hello", font, 48};
    text.setFillColor(sf::Color::Red);
    text.setStyle(sf::Text::Regular);
    text.setPosition(200, 200);
    ...
    while(running) {
       sf::Event event;
       while(window.pollEvent(event)) {
           // handle event[s] ...
       }

       window.clear(sf::Color::Blue);

        window.draw(text); // program crashes when this is called.

        window.display();
    }
 



Here is the screenshot of the crash in debugger

Pages: [1]