mzero mzero - 3 months ago 23
C++ Question

Font not loading

I spent the last 2 hours trying to figure out what is wrong with my code. Some solutions on Google/StackOverflow didn't change the problem.

Here's this simple code :

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

int WinMain()
sf::RenderWindow window(sf::VideoMode(1280, 720), "BBS");

// redirect sfml stderr to this file
std::ofstream file("sfml-log.txt");
std::streambuf* previous = sf::err().rdbuf(file.rdbuf());

sf::err() << "ABCD" << std::endl;

sf::Font font;
// this line fail and make stderr crash
sf::err() << "XYZ" << std::endl;
return 0;

The file "sfml-log.txt" is created but it contain everytime the same thing :

Failed to load font "

For the context I launch the executable within the same directory as sfml DLLs.
I tried to modify the font path to "arial.ttf" and put it in the same directory, nothing changed.

Thanks in advance for your help.


Ok, I just solved it.

I was compiling with debug settings in VS and was linking with

sfml-graphics.lib sfml-window-s.lib sfml-window.lib sfml-system-s.lib sfml-system.lib

instead of

sfml-graphics-d.lib sfml-window-s-d.lib sfml-window-d.lib sfml-system-s-d.lib sfml-system-d.lib