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

Author Topic: Font File won't load (VS 2022 SFML 3.0.0)  (Read 34 times)

0 Members and 1 Guest are viewing this topic.

opossum

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Font File won't load (VS 2022 SFML 3.0.0)
« on: May 16, 2025, 07:14:30 pm »
Coding in Visual Studio 2022, using SFML-3.0.0 and C++(ISO C++20 Standard).
Release and Debug versions both at x64.

My RELEASE Version of the build fails to load a font file, meanwhile the DEBUG version works perfectly fine.
If I run the code from inside VS2022 or the generated .exe file in it's own folder, DEBUG version works both ways, but RELEASE won't work, neither in VS2022 or in it's own folder. 

I have also inserted necessary font files, and .dll files inside the folder containing the .vcxproject file.

I have also made sure to put the font file in question "OCR_a.ttf" in the folder where the generated .exe file is, for me it is in "\My_Project\x64\Debug\" or "\My_Project\x64\Release\".

I have triple checked I am using the correct .lib files in the Project RELEASE properties. They are as follows: "sfml-window.lib;sfml-system.lib;sfml-graphics.lib". My DEBUG version uses same libraries but with "-d" added to them.

The correct (I assume) .dll files are also inserted into the folder where the .exe file is generated (both the RELEASE and DEBUG folder stated above), specifically: "sfml-graphics-3.dll", "sfml-system-3.dll" and "sfml-window-3.dll". The DEBUG folder contains the .dll files with "-d" added to them.

This is the way I call the font class in code:
   sf::Font main_font;

   if (!main_font.openFromFile("OCR_a.ttf")) {
      std::cout << "\nERROR\n";
      return -1;
   }

   main_font.setSmooth(0);

I have also tried using the openFromMemory() function, and also the constructor:
sf::Font main_font("OCR_a.ttf");
Neither of them worked in the Release version.

I have also tried out a different font file "arial.ttf", it also doesn't work in RELEASE, but in DEBUG it works.

When I run the program the console outputs this message:

Failed to load font (failed to create the font face)
    Provided path: ""
    Absolute path: ""

As you can see the if statement above will instantly return -1 and exit the function that is called. If I do allow the code to continue, eventually all my sf::Text objects are unusable and lead to:
"Exception: Read access violation. this->_Myproxy was 0xA."

Is there a specific way I can explicitly say in the code: "Look for the file in the .exe folder!"?

Let me restate it again, the DEBUG version runs it completely fine, launching from inside the VS2022 or the folder generated by the .exe file. I can provide screenshots of my project properties and file structure if necessary.

I am a relative beginner, so you could assume I have setup something improperly when I tried to test out the RELEASE version. I would like to avoid doing Static linking, unless it is absolutely necessary.

Any help is appreciated, it might be an incorrect project setting, or I am doing something wrong! Thanks in advance! :)