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

Author Topic: Error accessing files to load fonts  (Read 1582 times)

0 Members and 1 Guest are viewing this topic.

A_Sentient_Tomato

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Error accessing files to load fonts
« on: March 08, 2020, 08:15:40 pm »
Hello. I'm a student using SFML for one of my projects (C++) and this error has been driving me nuts.

I'm trying to load a truetype font using SFML. All other SFML features that I've used so far have been working fine (although none of them involve reading files), but this specific one seems to be failing every time.
I've tried to load the font using loadFromFile() and loadFromStream(). The first returns no error (but the method returns "false") and the latter prints "Failed to load font from stream (failed to create the font face)".

This led me to think that SFML is having trouble reading files from my disk. However, the ttf file is definitely in the working directory - I've checked this by having the program create a file and checking the directory it appears in. The ttf file is also definitely valid (I can open it using other software) and appropriately named.

As part of this project, I've already used another library (pugixml) to read xml files, and have had no trouble reading from the same directory that I am trying to access here, so this doesn't seem to be a permission problem.

Here is the relevant code:



        sf::Font font;
        sf::FileInputStream stream;
        if (!stream.open("arial.ttf")) {
                std::cout << "error\n";
        }

        if (!font.loadFromStream(stream)) {
                std::cout << "error1\n";
        }
        std::ofstream outfile("testfile.txt");

        if (!font.loadFromFile("arial.ttf")) {
                std::cout << "error3\n";
        }

 

All three of these errors are triggered. I've #include'd <SFML\Graphics.hpp> at the top of the file.

Any help would be really appreciated! Thank you in advance!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Error accessing files to load fonts
« Reply #1 on: March 09, 2020, 11:43:30 pm »
It's worth noting that it's possible that the software you are using may have separate locations for local input and local output, although this is unlikely. This is a "feature"... ;D

Best way to be absolutely certain that the location is correct is to use an absolute path and filename.

This may not be the problem but it's worth being sure about this before moving on to something else.

After that, I'd try multiple fonts. It may be a format 'not-quite-right' for some reason. If you want to be certain, try the same fonts that can be checked by someone else e.g. https://github.com/Hapaxia/MyPracticeBeginnerGames/blob/master/Puzza/resources/arial.ttf
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*