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

Author Topic: Unable to load image SFML 2.3  (Read 4081 times)

0 Members and 2 Guests are viewing this topic.

gop_t3r

  • Newbie
  • *
  • Posts: 35
    • View Profile
Unable to load image SFML 2.3
« 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?
« Last Edit: June 04, 2015, 12:51:55 am by gop_t3r »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Unable to load image SFML 2.3
« Reply #1 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, not your entire game with avatars and whatnot ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Unable to load image SFML 2.3
« Reply #2 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...)

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, and like this for linux.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Unable to load image SFML 2.3
« Reply #3 on: June 03, 2015, 10:58:07 pm »
What exact error messages do you get?

gop_t3r

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Unable to load image SFML 2.3
« Reply #4 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Unable to load image SFML 2.3
« Reply #5 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gop_t3r

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Unable to load image SFML 2.3
« Reply #6 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Unable to load image SFML 2.3
« Reply #7 on: June 04, 2015, 01:15:52 am »
There's still a bunch of unanswered questions from dabbertorres, Jesper Juhl and me.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: