SFML "failed to create the font face" issue
Asked Answered
P

5

7

I'm using SFML in Visual Studio 2015 to make a game that requires me to print text. I try to load fonts and keep getting an error that says "failed to create the font face". I've tried loading several different fonts and none of them work, and they are in the correct directory, which is the folder where my project is located.

This is literally all it is, and it doesn't work:

 sf::Font font;
    if (!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;

The ttf file for arial is in the same folder as the project itself, which is what seems to solve the problem for everyone else I find online who has the same issue. Any idea why the font still won't load?

Premonition answered 18/4, 2016 at 22:12 Comment(4)
Are you absolutely certain the current working directory when running the problem is the one where those font files are (i.e. did you verify it by for example printing the cwd before trying to load the file)? Did you try using an absolute rather than a relative path to the file?Heavenly
@DanMašek Yeah I did both of those things and I still get the same issue.Premonition
Hmm. Are you trying this in Debug mode? If so, are you linking with the debug version of SFML?Heavenly
@DanMašek yes, and the same error both with debugging and running it normally.Premonition
C
5

The simple answer is, the file is not in your current working directory when you run your executable.

Try to put in a fully qualified filename. It will work.

Using Visual Studio, most likely this is the directory where your .vcxproj file resides.

If this does not work, you can find out what your current working directory is by checking this post for a generic way how to find out your current directory.

As a quick hack, you could just create a file when your program starts. Start once and check where the file gets created. This is the current directory.

Clevey answered 19/4, 2016 at 11:47 Comment(0)
I
1

I fixed with this:

sf::Font font;
if (!font.loadFromFile("../arial.ttf")){
   return EXIT_FAILURE;
}

I'm using CLion on Ubuntu using SMFL also.

Ils answered 29/7, 2019 at 12:50 Comment(0)
I
1

To add to this, I was experiencing this same error when I thought I'd had everything typed properly. What ultimately ended up being the issue was that I had written .tff for the font file rather than .ttf, which, once corrected, fixed the problem.

Isosceles answered 2/6, 2020 at 23:27 Comment(0)
P
1

My TTF file had no permissions once extracted from its archive. Executing chmod 644 font.ttf fixed the problem.

Perez answered 18/10, 2021 at 16:51 Comment(0)
L
0

May be you can check the "Additional dependencies" option, where it's have to be this format "sfml-graphics-d.lib" in debug configuration and "sfml-graphics.lib" in release. this option is load in "Property << Linker << Input".

Looselimbed answered 30/8, 2024 at 12:53 Comment(2)
The question is about a run-time failure to load a font file, rather a linking error. Linker settings seem like an unlikely cause.Plumose
yeah! Howerver, I got a similar problem, and I finally sloved this problem by modifing the link configure. There are a debug lib and a release lib is different when you use the loadFromFile() funtion. That's could make that error as above. May be he was in that situation, may be not. I just shared my solution when I got in this situation.Looselimbed

© 2022 - 2025 — McMap. All rights reserved.