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

Author Topic: my path is correct but still cannot load the file  (Read 2077 times)

0 Members and 1 Guest are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
my path is correct but still cannot load the file
« on: April 15, 2015, 10:36:11 pm »
can someone take a look at the picture below?
why im getting that error?
the image is already at the working directory
this is the code

if(!texture.loadFromFile("airplane.jpeg");
{
std::cout <<"error";
}

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: my path is correct but still cannot load the file
« Reply #1 on: April 15, 2015, 10:46:29 pm »
Just because the image file is in the same directory as your executable does not mean that it is in the current working directory when that executable is launched.
The current working dir can be set by another application that launches yours (like your IDE or the Windows cmd shell). Unless you explicitly change the cwd at runtime to be the same as the dir holding your executable you cannot make such assumptions.
If you want to be completely independent of where your app is launched from when loading resources, then obtain the path to your executable at runtime and load all resources relative to that path.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: my path is correct but still cannot load the file
« Reply #2 on: April 15, 2015, 10:48:10 pm »
In Visual Studio, the working directory can be set as follows:

Project Properties > Configuration Properties > Debugging > Working Directory
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: my path is correct but still cannot load the file
« Reply #3 on: April 15, 2015, 11:26:42 pm »
Also make sure you use the correct file extension / name. (jpeg instead of jpg for example)
And don't put a ; after your if.

Dejan Geci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: my path is correct but still cannot load the file
« Reply #4 on: April 16, 2015, 09:14:56 am »
And don't put a ; after your if.

This. You terminated the IF prematurely, so
std::cout <<"error";
will always execute.

As for the loading problem, go into your "Debug" directory and see if the JPG is there with your EXE.
Make sure the file name is correct - JPG or JPEG, and finally, make sure that the image is valid and it loads properly in editors and viewers.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: my path is correct but still cannot load the file
« Reply #5 on: April 16, 2015, 04:23:00 pm »
"Just because the image file is in the same directory as your executable does not mean that it is in the current working directory when that executable is launched."
if you create a project, the working directory is where your project file is by default. or im wrong?

i have another problem
the first picture , it is loading the file succesfully and displays it
but theres a warning in my console window
in the second picture, it looks like my sfml doesnt support jpeg file, im using sfml 2.2 of nightly's build

electruxck

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: my path is correct but still cannot load the file
« Reply #6 on: April 20, 2015, 05:59:21 pm »
instead of jpeg, it should be jpg (no 'e')
hence,

if(!texture.loadFromFile("airplane.jpeg");
{
std::cout <<"error";
}

should be

if(!texture.loadFromFile("airplane.jpg");
{
std::cout <<"error";
}

 

anything