SFML Error loading font under Windows

2019-02-21 06:30发布

问题:

I've been trying to develop a cross-platform application for Windows and Linux using SFML. Everything's been going fine so far, except that the Windows version cannot seem to load fonts. I have no issues under Linux however. I did my research and made sure the file was in place, according to where I was executing from, but sf::Font::loadFromFile still returns false.

Here's the code:

sf::Font _font;
sf::Text _text;

if (!(_font.loadFromFile("resources/fonts/arial.ttf")))
{
    std::cerr << "Error loading font '" + font + "'" << std::endl;
    return;
}
_text.setFont(_font);

Do you guys have any idea what I'm doing wrong here?

I'm using SFML 2.3, linking statically.

Update: the loadFromFile methods doesn't work either for textures. I can check programmatically that the files are in place, and opening them with ifstreams works fine, but SFML cannot seem to access them.

回答1:

Found the problem, as usual my fault: I was using the release version of the library, but my VS project was in Debug!



回答2:

Check to make sure your file is in the correct directory and make sure the spelling is exact as well. Usually this is the most common source of error.