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

Author Topic: [SOLVED] Unabled to load file problem - loadFromFile.  (Read 940 times)

0 Members and 1 Guest are viewing this topic.

ram.ggi191

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
[SOLVED] Unabled to load file problem - loadFromFile.
« on: December 03, 2024, 12:02:42 pm »
Hi!

I got a big white square on the screen once I run the code with the error message "Unable to load file"

I assume it is IDE setting problem, which the difference of execution directory and debug directory but not sure how should I adjust those IDE directions on the project option. I posted the error message in the console and my project settings

source code
        Labyrinth.loadFromFile("asset/labyrinth.png");

        int index = 0;
        for (int i = 0; i < 8; i++)
        {
                for (int j = 0; j < 4; j++)
                {
                        LabyrinthPieces[index] = new sf::Sprite(Labyrinth, sf::IntRect(i * 8, j * 8, 8, 8));
                        LabyrinthPieces[index]->setScale(2.0f, 2.0f);
                        index++;
                }
        }

        Players.loadFromFile("asset/players.png");
« Last Edit: December 05, 2024, 03:06:12 pm by ram.ggi191 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11049
    • View Profile
    • development blog
    • Email
Re: Unabled to load file problem - loadFromFile.
« Reply #1 on: December 03, 2024, 03:24:27 pm »
You're likely linking SFML release libraries (without -d suffix) in debug mode or SFML debug libraries (with -d suffix) in release mode.

Make sure to use the SFML debug libraries in debug mode (e.g. sfml-graphics-d.lib) and the SFML release libraries in release mode (e.g. sfml-graphics.lib).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ram.ggi191

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Unabled to load file problem - loadFromFile.
« Reply #2 on: December 04, 2024, 01:32:40 am »
Thanks for your reply!

However, I still get the dead white screen, even when I fix the additional dependencies to fit as the right mode (like using non -d.lib for the release -d.lib for  debugger mode)

here is the picture of my dependencies set up below in the release mode.

Hapax

  • Hero Member
  • *****
  • Posts: 3387
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Unabled to load file problem - loadFromFile.
« Reply #3 on: December 04, 2024, 02:48:17 pm »
Have you tried absolute paths to make sure the image is able to be loaded?
Presumably it's not loading because it can't find it but it might not be able to read it.

If it can't find it, it would likely be due to local paths and where your IDE is looking for them. How to change this depends on the IDE.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ram.ggi191

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Unabled to load file problem - loadFromFile.
« Reply #4 on: December 05, 2024, 03:05:57 pm »
Oh yes, the path was the problem, the engine didn't recognised the folder path then I copied my asset file to the project file, linked it and then it works!

Still I need to figure out why it doesn't recognised the path of the directory yet.   

kojack

  • Sr. Member
  • ****
  • Posts: 346
  • C++/C# game dev teacher.
    • View Profile
Re: [SOLVED] Unabled to load file problem - loadFromFile.
« Reply #5 on: December 06, 2024, 12:11:41 am »
Your output directory (where the .exe file is put) is $(SolutionDir), the location of the .sln file.
Your working directory (where it will look for asset/labyrinth.png) is $(ProjectDir), the location of the .vcxproj file.
So sounds like your asset directory isn't in the project directory where Visual Studio has been told to look for it.
(I always either change $(ProjectDir) to $(TargetDir), which looks where the .exe was put, or in code I find the exe path and change working directory to it)

 

anything