Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 won't find resource files during debugging

I'm currently learning SFML and I have this bit of code in my program:

if (!texture.loadFromFile("Textures/plane.png"))
{
    std::cout << "Error loading texture plane.png" << std::endl;
}

and I have file plane.png inside folder Textures that is in the same folder as executable. When I run the executable through windows explorer, the texture loads without any issue, but when I run it as debug inside VS, I get this output:

  Failed to load image "Textures/plane.png". Reason: Unable to open file
  Error loading texture plane.png

First line is from SFML, second from my program.

Is there a way to fix this? I also tried putting the textures folder to several different places in the projects root folder, but no change.

like image 581
isklenar Avatar asked Feb 16 '23 20:02

isklenar


1 Answers

Try this. Go to project Configuration Properties. Look at the Debugging tab. There should be a "Working Directory" field. The working directory may be different from the directory where your executable sits. You can change the working directory to be the same as the directory you run the executable from in windows explorer so the executeable will be able to find the file using the same relative path.

(Note: I use VS 2010, so exact names of options, etc. may vary).

like image 56
A.E. Drew Avatar answered Mar 07 '23 12:03

A.E. Drew