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

Author Topic: sf::Texture loadFromFile unable to open file [Visual Studio 2015]  (Read 6538 times)

0 Members and 1 Guest are viewing this topic.

Zerima

  • Newbie
  • *
  • Posts: 5
    • View Profile
From what I've read the image should be in the output directory / intermediate directory(check attachment) and the image is indeed in the correct location.

I have also rechecked the property settings with the sfml setup tutorial and they are correct too and I've tried changing the image to a png and bmp, but still getting the same error.

       
sf::Texture backGround;
if (!backGround.loadFromFile("game.jpg"))
{
        std::cout << "Failed to load image." << std::endl;
        return -1;
}
 

I've also tried using loadFromStream and it doesn't work either.

sf::FileInputStream test;
test.open("game.jpg");
sf::Texture backGround;
if (!backGround.loadFromStream(test))
{
        std::cout << "Failed to load image." << std::endl;
        return -1;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: sf::Texture loadFromFile unable to open file [Visual Studio 2015]
« Reply #1 on: May 27, 2016, 10:17:27 pm »
What is your working directory set to?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zerima

  • Newbie
  • *
  • Posts: 5
    • View Profile
What is your working directory set to?
If you're talking about the one that is configuration properties -> debugging it's the same as the output directory / intermediate directory.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: sf::Texture loadFromFile unable to open file [Visual Studio 2015]
« Reply #3 on: May 27, 2016, 10:31:05 pm »
I don't see an exe in the directory you screenshotted, so is that really the output directory?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zerima

  • Newbie
  • *
  • Posts: 5
    • View Profile
I don't see an exe in the directory you screenshotted, so is that really the output directory?
When I click the drop down arrow then browse it takes me to that folder I screenshotted in my first post.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::Texture loadFromFile unable to open file [Visual Studio 2015]
« Reply #5 on: May 27, 2016, 11:34:05 pm »
If the working directory in the debugging settings tab is also set to $(SolutionDir)$(Configuration)\, then it's not a mystery why the resources can't be found.
Resources are searched relative to the working directory and the $(Configuration) part means, that the dir will be set to the Debug or Release sub-directory depending on the configuration you've currently selected.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zerima

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: sf::Texture loadFromFile unable to open file [Visual Studio 2015]
« Reply #6 on: May 27, 2016, 11:40:34 pm »
If the working directory in the debugging settings tab is also set to $(SolutionDir)$(Configuration)\, then it's not a mystery why the resources can't be found.
Resources are searched relative to the working directory and the $(Configuration) part means, that the dir will be set to the Debug or Release sub-directory depending on the configuration you've currently selected.
It is not the same, but it still takes me to the same folder regardless when I hit browse.

Zerima

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: sf::Texture loadFromFile unable to open file [Visual Studio 2015]
« Reply #7 on: May 28, 2016, 12:14:45 am »
I went to the configuration manager and changed the "active solution configuration" from debug to release and it's working.

Edit: The active solution configuration can actually be either debug or release, but the "configuration" for the project has to be on release.
« Last Edit: May 28, 2016, 12:29:13 am by Zerima »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Texture loadFromFile unable to open file [Visual Studio 2015]
« Reply #8 on: May 28, 2016, 02:55:20 pm »
The folder that was you provided a screenshot for in the first post was indeed the $(ProjectDir) so, if run from within Visual Studio, will look for its resources there. As an aside, the DLLs are not needed here; they should only be next to the built EXEs (e.g. Debug/ and Release/)
If you run the EXE outside of Visual Studio, the working directory is no longer the project directory but is now the EXE's directory. This means that the resources will need to exist in the working directory (for running inside VS - while "working" on it), and also in the Debug/ and Release/ folders (along with any other build folders).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*