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

Author Topic: Failed to load image  (Read 747 times)

0 Members and 1 Guest are viewing this topic.

jonathan1986

  • Newbie
  • *
  • Posts: 1
    • View Profile
Failed to load image
« on: March 09, 2023, 07:52:22 am »
Hello
I need some help
I downloaded SFML and built it under visual studio 2022.
It compiled and worked till I ha to load files and images.
I tried 2 versions 32 and 64 bit for windows and both gave me the same error:
"Failed to load image".
There was not any explanation for why it occured

kojack

  • Sr. Member
  • ****
  • Posts: 314
  • C++/C# game dev teacher.
    • View Profile
Re: Failed to load image
« Reply #1 on: March 09, 2023, 08:41:29 am »
The most likely cause is that the path to the image doesn't fit with the working directory.
One annoyance with Visual Studio is that by default it sets the working directory to $(ProjectDir). This means any relative file access will be relative to where your project file is, not where the exe was built.
You can change that in the project properties, under Debugging / Working Directory. I set it to $(TargetDir), which is where the exe goes.

So the things to check:
- where is the exe being placed?
- where is the image you are trying to load?
- what string did you give SFML as the path to the image?

(This setting only has an effect when running from inside of Visual Studio. If you run the exe from explorer, the working directory is set to where the exe is)

 

anything