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

Author Topic: Unable to load file : configuration problem  (Read 2854 times)

0 Members and 1 Guest are viewing this topic.

Hindi

  • Newbie
  • *
  • Posts: 20
    • View Profile
Unable to load file : configuration problem
« on: May 02, 2012, 09:48:26 am »
I'm trying to run an SFML project on code block on a new computer and there is a bug : every image loading  return false. The working directory seems to be the good one, I have no link error message, and this code works on another computer with the aproximate same configuration : SFML 1.6, windows 7 x64, NVIDIA graphic card (GT520M here).
Any advice ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Unable to load file : configuration problem
« Reply #1 on: May 02, 2012, 09:55:30 am »
Quote
every image loading  return false
With what error message?

Quote
The working directory seems to be the good one
How can you see that "it seems to be the good one"? :P
Laurent Gomila - SFML developer

Hindi

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Unable to load file : configuration problem
« Reply #2 on: May 02, 2012, 10:47:21 am »
The error message is : "Unable to load file"

Quote
The working directory seems to be the good one
How can you see that "it seems to be the good one"?

I can configure an execution directory and an execution working directory. I guess that the second one is the working directory.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Re: Unable to load file : configuration problem
« Reply #3 on: May 02, 2012, 09:10:32 pm »
I can configure an execution directory and an execution working directory. I guess that the second one is the working directory.

To verfiy just browse to the folder wher the .exe file is located, put all the needed images right next to the .exe, make sure you're paths in the application are like "image.png" and then double click the .exe file to run the application. If you still get the same error there seems to be another problem.

Maybe you can provide a minimal example code and tell us which image format you're trying to load.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hindi

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Unable to load file : configuration problem
« Reply #4 on: May 02, 2012, 11:16:18 pm »
Nothing changes after I move my images.
Nevertheless, something strikes me now : When I use the .exe file, the game window does not open itself, I have to open it myself and a console windows appear with errors, not the game windows. This also happens when I use the run button of Codeblock.

I'm using .png images.

The following code does not works :

Code: [Select]
#include <SFML/Graphics.hpp>

using namespace std;
using namespace sf;

int main()
{
imageFadePlay = new Image;
    if(!(*imageFadePlay).LoadFromFile("images/nouvellePartie_fade.png"))
    {
        cerr << "Image loading failed : nouvellePartie_fade.png" << endl;
    }
    else
    {
        spritePlay.SetImage(*imageFadePlay);
        spritePlay.SetPosition(position);
        spritePlay.Scale(m_scale);
    }

return 0;
}
« Last Edit: May 03, 2012, 08:03:29 am by Laurent »

AyaKamiki

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Unable to load file : configuration problem
« Reply #5 on: May 05, 2012, 11:10:26 pm »
I've just started with SFML and was having the same problem when I tried to compile the Pong example.
None of the sound, image or font files would load.
It turns out that the working directory wasn't set in my codeblocks project.
To fix this I went to 'Project - Properties - Build Targets' and set 'Execution working dir:' to bin\Release\

Hope that helps.

One other thing, I did find a mistake in the pong code, the path for the cheeseburger font appears to have been copied from another of the examples and points to the 'post-fx' directory instead of the 'pong' one, which threw me off a bit as I had to copy the datas/pong folder to my working directory for the files to be found and it still couldn't find that one file.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Re: Unable to load file : configuration problem
« Reply #6 on: May 05, 2012, 11:39:55 pm »
The following code does not works :

Your minimal example is not complete:

#include <SFML/Graphics.hpp>

int main()
{
    sf::Image imageFadePlay;
    sf::Sprite spritePlay;
    sf::Vector2f position(20.f, 20.f);
    float m_scale = 1.f;

    if(!imageFadePlay.LoadFromFile("images/nouvellePartie_fade.png"))
    {
        // This error message is actually not needed since SFML will print it's error message
        std::cerr << "Image loading failed : nouvellePartie_fade.png" << std::endl;
    }
    else
    {
        spritePlay.SetImage(imageFadePlay);
        spritePlay.SetPosition(position);
        spritePlay.Scale(m_scale);
    }

return 0;
}

Also this corrected version will not work on all systems. Under linux there's a known bug that doesn't let you do graphic stuff if you haven't initialized a sf::Window/sf::RenderWindow.

Although I'm not sure if this is also true for SFML 1.6.
I really advice to update to SFML 2rc. It will soon be the standard and 1.6 has many unresolved bugs and will not run with ATI graphic cards if it's linked dynamicly.
« Last Edit: May 05, 2012, 11:41:50 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/