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

Author Topic: Loadimage not working "Failed to load image"  (Read 3932 times)

0 Members and 1 Guest are viewing this topic.

Mauser_Maschine

  • Newbie
  • *
  • Posts: 1
    • View Profile
Loadimage not working "Failed to load image"
« on: March 21, 2021, 11:44:19 am »
This is the peak of my life's pain and suffering. I have been trying to load an image for a texture in visual studio 2019 for a few days now and it just can't find the image. I have been trying to find an answer for days and the only answer people give is "dOn'T mIx tHe dEbUg lIbS wItH tHe rEaLeAsE lIbs" when I put my vs config to release it can't find "SFML/Graphics.hpp". For god's sake, please help. I switched to sfml to avoid the stupid syntax of opengl glut and instead got this

KRS

  • Newbie
  • *
  • Posts: 19
  • The burning you feel?
    • View Profile
    • Email
Re: Loadimage not working "Failed to load image"
« Reply #1 on: March 21, 2021, 01:06:09 pm »
Man if you think that something is stupid it doesn't mean that it is. Got to be patient.
And to the problem, you need to set dependencies for both Debug and Release configuration. That means that when you go to project properties you need to set paths to SFML/lib and SFML/include for BOTH Debug and Release configurations. Just switch them using dedicated field and set needed paths again.  And don't forget about additional dependencies! They will be different for Debug and Release configuration, how to do this correctly explained here https://www.sfml-dev.org/tutorials/2.5/start-vc.php
As I remember if it's release then you need add "-s" to depensencie, if debug - "-s-d". Just read that article carefully, its all you need.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Loadimage not working "Failed to load image"
« Reply #2 on: March 21, 2021, 01:06:52 pm »
"failed to load image" is usually related to an image not being in the specified path. maybe you put a relative path, maybe you moved the code files and forgot to move the image, maybe the image name is wrong (you need to include the extension, like "button.jpeg").

you also need to be more descriptive with your problem, since ranting is usually just ignored. your OS, SFML version, VSC version, how did you install SFML, how did you link it in VSC, the exact error mesages, etc...
Visit my game site (and hopefully help funding it? )
Website | IndieDB

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Loadimage not working "Failed to load image"
« Reply #3 on: March 21, 2021, 03:12:35 pm »
The first thing to check when a file can't load would be the working directory.
The default working directory in Visual Studio is the location of the vcxproject file.
The default working directory when running the executable directly (such as from explorer) is the location of the executable.
These are usually different locations, so any relative path (like "media/myimage.png") is going to look in a different spot for both.

You can change the Visual Studio working directory in project properties in the Debugging / Working Directory setting. Change it from $(ProjectDir) to $(TargetDir). Make sure you change it for any build types or platforms you use (debug, release, 32 bit, 64 bit).

(In my own projects, I manually change the working directory in code to match the executable, so I don't need to remember to fix the project settings)