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

Author Topic: Failed to load image!  (Read 20664 times)

0 Members and 1 Guest are viewing this topic.

lightbug

  • Newbie
  • *
  • Posts: 5
    • View Profile
Failed to load image!
« on: February 25, 2017, 07:18:37 pm »
First of all, Hello community!, (my English is bad), This is my first post:

I know that there are a lot of this kind of post, specially with the "failed to load image" problem, but in those post the solution was, "_hey man check if the working directory is the right one  _ Oohhh now it works thanks! " well, this is not the case (I guess).

My project consist of a bunch of classes that interacts each other making and managing different objects (sprites, text, sounds , etc) with differents manager classes (Object, resource, scene, etc), some call that an engine, doesnt matter. At first I used the codeblocks version (in codeblocks of course) and was great, no bugs, from one moment to another, "Failed to load image!" in one of my classes, in the main function works like a charm, still dont know why. Ok, I moved from codeblocks to Visual Studio.
I've download the 64 bit library for Visual Studio 2015, setting up everything like the tutorial page said . Then i got the same error "failed to load image", so I search in the internet, put the file (a jpg and a png) in every posible directory (really), put relative paths, absolute paths, implement "/" "//" "\" "\\" and all you can imagine. Then I put this code, this HAS to work:


#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>

int main()
{
        sf::Texture tex;
        if (!tex.loadFromFile("mirrorlakedawn.jpg"))
                return -1;     
       
        return 0;
}
 

Nothing, still "Failed to load image".

So, i come to here to ask for help, I dont know if is because of the 64 bit library, the debug or the static libraries. nothing works. In codeblocks i had a console application, here in VS too, the rest of SFML works perfectly

Thanks in advance

Regards

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Failed to load image!
« Reply #1 on: February 25, 2017, 07:38:55 pm »
Which error message do you get? LoafFromFile error message looks like "failed to load image. Reason:
  • ". Which 'reason' does it give to you?

lightbug

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Failed to load image!
« Reply #2 on: February 25, 2017, 07:50:26 pm »
In the console:
"Failed to load image"

that's it  :-\

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: Failed to load image!
« Reply #3 on: February 25, 2017, 07:54:39 pm »
If yiu are running from the editor check settings for run directory

lightbug

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Failed to load image!
« Reply #4 on: February 25, 2017, 08:41:37 pm »
If yiu are running from the editor check settings for run directory

what do you mean exactly with "run" directory? the project dir? the debug dir? I have the ".png" file all over the place, my PC is infected with this file, clearly the file in the wrong place is not the issue here.
anyway, my project path is: ".../(ProjectName)/(ProjectName)" inside i have these folders:
_ "Debug" with .obj files and "sfml-xxx-d-2.dll" files
_"x64" / "Debug" with .obj files
_ source with all headers and cpp files
_ SFML with all include and libs from sfml


JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Failed to load image!
« Reply #5 on: February 26, 2017, 06:32:39 am »
place
system("dir");
somewhere before you load it.  It will print the current working directory to the console window along with the files/folders in that directory. That will be the directory that SFML will be trying to load the image from.

Then remove the system call and pretend like I never told you to use it.

lightbug

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Failed to load image!
« Reply #6 on: February 26, 2017, 02:24:47 pm »
place
system("dir");
somewhere before you load it.  It will print the current working directory to the console window along with the files/folders in that directory. That will be the directory that SFML will be trying to load the image from.

Then remove the system call and pretend like I never told you to use it.

Thanks for the reply, here is code:

int main()
{
        system("dir");
       
        sf::Texture tex;
        if (!tex.loadFromFile("mirrorlakedawn.jpg")) {
                return -1;
        }
       
        return 0;
}


And the outcome:


 Volume in drive D is HDD7200
 Volume Serial Number is 59E2-31ED

 Directory of D:\VSProjects\2DEngineSFML\2DEngineSFML

02/25/2017  02:16 PM    <DIR>          .
02/25/2017  02:16 PM    <DIR>          ..
02/26/2017  10:12 AM             6,201 2DEngineSFML.vcxproj
02/25/2017  12:23 PM             3,246 2DEngineSFML.vcxproj.filters
02/25/2017  12:21 PM               165 2DEngineSFML.vcxproj.user
02/25/2017  02:19 PM    <DIR>          Debug
02/07/2017  03:37 PM            15,467 fire.png
02/25/2017  12:15 PM    <DIR>          middleware
02/07/2017  04:00 PM           510,916 mirrorlakedawn.jpg
12/04/2014  04:09 PM           440,832 openal32.dll
02/25/2017  12:15 PM    <DIR>          resources
02/11/2017  03:42 AM         1,014,272 sfml-audio-2.dll
02/11/2017  03:42 AM           916,992 sfml-graphics-2.dll
02/11/2017  03:42 AM           138,752 sfml-network-2.dll
02/11/2017  03:42 AM            53,760 sfml-system-2.dll
02/11/2017  03:42 AM           112,640 sfml-window-2.dll
02/26/2017  10:10 AM    <DIR>          source
02/24/2017  07:20 PM               980 UI_basicButtom.png
02/25/2017  02:06 PM    <DIR>          x64
              12 File(s)      3,214,223 bytes
               7 Dir(s)  276,529,680,384 bytes free
Failed to load image "Press any key to continue . . .

So the working directory is "D:\VSProjects\2DEngineSFML\2DEngineSFML" :



still nothing, "failed to load image"

thanks again

lightbug

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Failed to load image!
« Reply #7 on: February 26, 2017, 02:58:09 pm »
Update:

After testing everything I decided to create a new project (win32), this time i downloaded the 32 bits version of sfml and it works. This time if the image isn't there it gives me a reason, for example "Failed to load image "fire.png". Reason: Unable to open file"

I guess i'll be using the 32bits libraries instead, Although this is clearly not the solution.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Failed to load image!
« Reply #8 on: February 26, 2017, 03:27:29 pm »
You probably were mixing libraries, e.g. debug and release, x64 vs x86.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/