Visual Studio 2012 will not find resource files during debugging

I am 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 a plane.png file inside the Textures folder, which are in the same folder as the executable. When I run the executable through Windows Explorer, the texture loads without any problems, but when I run it as debugging inside VS, I get this output:

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

The first line is from SFML, the second is from my program.

Is there any way to fix this? I also tried putting the texture folder in several different places in the root folder of the projects, but no changes.

+4
source share
1 answer

Try it. Go to the "Project Configuration Properties" section. Take a look at the Debug tab. There must be a "Working Directory" field. The working directory may differ from the directory in which your executable file is located. You can change the working directory to be the same as the directory in which you run the executable from Windows Explorer so that the executable can find the file using the same relative path.

(Note: I am using VS 2010, so the exact names of the parameters, etc. may vary).

+8
source

Source: https://habr.com/ru/post/1492744/


All Articles