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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With