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

Author Topic: Problem about function loadFromFile() of class sf::Font  (Read 843 times)

0 Members and 1 Guest are viewing this topic.

eriskcn

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Problem about function loadFromFile() of class sf::Font
« on: June 23, 2023, 05:30:21 pm »
Hello everyone,

I'm new to SFML and I'm encountering an issue with the `loadFromFile()` function in the `sf::Font` class. Below is my source code:

```
sf::Font font;
if (!font.loadFromFile("C:\\Windows\\Fonts\\Arial.ttf"))
{
    return -1;
}
```

When I run the program with Visual Studio 2022, the `Microsoft Visual Studio Debug Console` displays "Failed to load from file "" (failed to create the font face)". What can I do to fix this issue?

Thank you all very much!

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problem about function loadFromFile() of class sf::Font
« Reply #1 on: June 23, 2023, 10:16:12 pm »
First, it's much simpler to use single slashes (instead of double-backslashes)

Apart from that, I'd recommend checking the absolute path and filename is correct. (Note that it's case sensitive and "Arial" might be wrong; it's the filename you need, not the font's (or font group's) name).
I'd suggest using "arial.ttf". That seems to be the filename of it.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: Problem about function loadFromFile() of class sf::Font
« Reply #2 on: June 23, 2023, 10:47:40 pm »
When I run the program with Visual Studio 2022, the `Microsoft Visual Studio Debug Console` displays "Failed to load from file "" (failed to create the font face)".

What can I do to fix this issue?
That usually happens if you use release libraries in debug mode or debug libraries in release mode. Make sure that you use the libraries with the -d suffix in debug mode and the ones without -d suffix in release mode.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eriskcn

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Problem about function loadFromFile() of class sf::Font
« Reply #3 on: June 24, 2023, 08:56:32 am »
Thank you so much, I fixed this problem  :-*
« Last Edit: June 24, 2023, 09:31:53 am by eriskcn »