SFML community forums

Help => General => Topic started by: gop_t3r on June 03, 2015, 10:21:51 pm

Title: Unable to load image SFML 2.3
Post by: gop_t3r on June 03, 2015, 10:21:51 pm
Before you start barking at me about incorrect file paths, I'd like to remind you that I've been using SFML for a long time on both Windows and Linux. I have ported an app from Linux to Windows on Visual Studio and I have the assets directory under the VC++ Project file directory. When I launch my program it says that SFML is unable to load the image. I have used an older version of SFML under my Linux machine so I don't know what's exactly changed with regards to how SFML loads images. The image I have is a *.png file so I assume SFML supports it because they use a png example on the tutorials. I've also duplicated the assets folder everywhere (silly, I know) and I still get the same error. I even added the absolute path of the image file and I still get the same error. This code runs under Linux just fine, so I honestly don't see how it can't work under Windows 8.1 64-bit. All libraries are linked and SFML runs just fine. I even compiled and ran the tutorial example and that ran fine too. I'm convinced that this is a SFML 2.3 bug.

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

        sf::Texture texture;
        if (!texture.loadFromFile("assets/graphics/explorer.png"))
                cerr << "Unable to load image!" << endl;

        sf::Sprite sprite;
        sprite.setTexture(texture);

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                window.draw(sprite);
                window.display();
        }

        return 0;
}

This is how I load the image. Before you start pointing the finger at pointers I also tried them as raw variables, but I still get the same error. I've also checked the drawing method, but that isn't important right now because not even the image is being loaded. I might roll back to version 2.1 since that was the most stable version on my part.

Can anyone explain why on SFML 2.3 loading images has suddenly stopped working? :-)) Is there another dependency I'm supposed to also link to?
Title: Re: Unable to load image SFML 2.3
Post by: Nexus on June 03, 2015, 10:38:08 pm
You're the first to report that problem. I'm using SFML 2.3 on Windows 8.1 and loading textures just fine.

Do the examples shipped with SFML work for you?

And for the sake of reproducibility and focus on the issue, you should try a minimal complete example (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368), not your entire game with avatars and whatnot ;)
Title: Re: Unable to load image SFML 2.3
Post by: dabbertorres on June 03, 2015, 10:38:45 pm
Are you running the program from inside VS or outside of VS?

I can't remember the running directory that VS uses, but that'd be it...
(this might help... (http://stackoverflow.com/a/1103005/1787213))

Besides that though, I just use a function to get the location of my running program, and then make the path to resource files from there.
Like this for windows (https://github.com/dabbertorres/gfs/blob/master/src/WinImpl/gfs.cpp#L25), and like this for linux (https://github.com/dabbertorres/gfs/blob/master/src/WinImpl/gfs.cpp#L25).
Title: Re: Unable to load image SFML 2.3
Post by: Jesper Juhl on June 03, 2015, 10:58:07 pm
What exact error messages do you get?
Title: Re: Unable to load image SFML 2.3
Post by: gop_t3r on June 04, 2015, 12:54:50 am
I've updated the question so it can include a minimal-working example of the problem I have. As you can see, I load in the texture through the file, then I allocate the texture to a sprite which is then drawn. The error 'Unable to load image' is the only error that is shown up on the console - no other errors appear. This is strange because in earlier versions of SFML there used to be an error message. Also, I downloaded this package from SFML's website and it was the 64-bit version for Visual Studio 2013. Although that's obvious, it was just for reassurrance sake. Can anyone run the code in the original post and see if they're experiencing a problem? Should I just use the 32-bit version of the libraries instead?
Title: Re: Unable to load image SFML 2.3
Post by: Nexus on June 04, 2015, 01:00:36 am
That depends on how you compile your project and not on your operating system!

32 bits is the default.
Title: Re: Unable to load image SFML 2.3
Post by: gop_t3r on June 04, 2015, 01:09:23 am
That depends on how you compile your project and not on your operating system!

32 bits is the default.

I'm running Windows 8.1 64-bit and have the 64-bit version of the library and am compiling and running the library on a 64-bit configration. I honestly don't know what's going on here. I should probably try an earlier version and see if that might help.
Title: Re: Unable to load image SFML 2.3
Post by: Nexus on June 04, 2015, 01:15:52 am
There's still a bunch of unanswered questions from dabbertorres, Jesper Juhl and me.