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

Author Topic: loadFromFile Failure  (Read 6605 times)

0 Members and 1 Guest are viewing this topic.

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
loadFromFile Failure
« on: July 03, 2015, 07:54:01 pm »
TL:DR for anyone having an issue similar to this:

Ensure you're using the correct library for your project configuration. Debug should correspond to -d, Static to -s in the lib filenames.

Don't be derpy like me, friends don't let friends mismatch library release configurations.  ;)
----------------------------------------------------------------------------------------------------
Greetings, I'm a new-comer to SFML, I work in the CG industry as a developer and I'm working with SFML for other academic purposes.

I'm having an interesting issue. The following code fails to load the texture in question. (The texture is a 128x32 png file with no transparency layer.) :

...
sf::Texture test;
sf::Sprite testSpr;
if(!test.loadFromFile("paddle.png")) {
    cerr << "I'd like more debug info than this.";
    return EXIT_FAILURE;
}
testSpr.setTexture(test);
...
 

paddle.png is a typical power of two texture. It is located in the working directory, which was set using VS2010's project debugging configuration. Even an execution from cmd within the appropriate working directory fails:

Checking the error stream reveals the following error (which makes no sense to me)
Quote
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>Pong.exe 2> err.log

C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>type err.log
I'd like more debug info than this.
Failed to load image "
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>dir paddle.png
 Volume in drive C has no label.
 Volume Serial Number is XXXX-XXXX

 Directory of C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug

07/03/2015  10:24 AM               424 paddle.png
               1 File(s)            424 bytes
               0 Dir(s)  902,470,395,904 bytes free

C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>

That's not a typo, there is only one quote character in the stream output for the lib error stream output. The string literal provided as argument is clearly not empty.

Anyone have any ideas?
« Last Edit: July 03, 2015, 09:51:15 pm by trashcanman980 »

kitteh-warrior

  • Guest
Re: loadFromFile Failure
« Reply #1 on: July 03, 2015, 08:00:27 pm »
Can you provide the .png file that is causing the problem? Have you tried this with other image files/converting your non-transparent PNG to a JPEG (as a test)?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: loadFromFile Failure
« Reply #2 on: July 03, 2015, 08:02:50 pm »
If this is a 8bit png then that would explain things since they are not supported.
Are you sure the cwd is what you think it is? Perhaps output the result of getcwd() when loading fails.

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #3 on: July 03, 2015, 08:05:58 pm »
I kept the prompt open:

Quote
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>chdir
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug

C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>echo %CD%
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug

So the CWD should be good.

As for the .png, it was generated in about 30 seconds this morning using mspaint packaged with windows 8.1. It's just a prototype standin. I've attached it here. I've tried generating others in various styles, no dice.
« Last Edit: July 03, 2015, 08:14:20 pm by trashcanman980 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: loadFromFile Failure
« Reply #4 on: July 03, 2015, 08:14:35 pm »
Depending on how you launch the application, your shell or visual studio or other stuff may change the programs cwd. Hence my suggestion to validate it with a call to getcwd() at runtime ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
AW: loadFromFile Failure
« Reply #5 on: July 03, 2015, 08:20:40 pm »
Is "Failed to load image "" really the error you get? Because that means SFML never got the filename which I can't really explain. Are you using any odd compiler flags? Did you build SFML from source?
« Last Edit: July 03, 2015, 08:25:49 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/

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #6 on: July 03, 2015, 08:22:32 pm »
Solid Suggestion, Attempted as follows:

        if(!test.loadFromFile("paddle.png")) {
                cerr << "*Violent Explosion*" << endl;

                char path[FILENAME_MAX];
                _getcwd(path, sizeof(path));
                printf ("Work Dir : %s", path);

        }
 

Output:
Quote
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>Pong.exe 2> err.log
Work Dir : C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>type err.log
*Violent Explosion*
Failed to load image "
C:\Users\<ME>\Documents\Visual Studio 2010\Projects\pong\x64\Debug>

Verified CWD is appropriate during load at runtime.

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #7 on: July 03, 2015, 08:24:49 pm »
Here's my full invocation, I downloaded the libraries pre-compiled.

Quote
/I"C:\Users\<ME>\Desktop\SFML-2.3\include" /Zi /nologo /W3 /WX- /Od /D "_MBCS" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"x64\Debug\pong.pch" /Fa"x64\Debug\" /Fo"x64\Debug\" /Fd"x64\Debug\vc100.pdb" /Gd /errorReport:queue
« Last Edit: July 03, 2015, 08:43:10 pm by trashcanman980 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: loadFromFile Failure
« Reply #8 on: July 03, 2015, 08:47:20 pm »
Does it work if you explicitly load it into an sf::Image first?
sf::Image image;
if (!image.loadFromFile("paddle.png"))
{
    std::cerr << "Image failed to load from file." << std::endl;
    return EXIT_FAILURE;
}
sf::Texture texture;
if (!texture.loadFromImage(image))
{
    std::cerr << "Texture failed to load from image." << std::endl;
    return EXIT_FAILURE;
}
sf::Sprite sprite(texture);
// ...



p.s. This:
cerr << "*Violent Explosion*" << endl;
made me chuckle  ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #9 on: July 03, 2015, 08:53:18 pm »
Hapax, Thanks for the suggestion. I gave it whirl, but the Image failed to loadFromFile as well:

Looking at the error stream reveals the same single quotation failure message.

Quote
Faled to load image "

I'm not sure how the string literal isn't making it over to where it belongs -.-. I also tried supplying the absolute path, but no dice. I've got to see to family affairs this afternoon, but thank you to everyone that's attempted to assist. I'll keep on this when i can return to my PC. I'll also give it a whirl on my UNIX platforms with the same file in order to isolate the file format from whatever issue may be causing this.
« Last Edit: July 03, 2015, 08:58:49 pm by trashcanman980 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: loadFromFile Failure
« Reply #10 on: July 03, 2015, 08:59:38 pm »
Ok, just guessing randomly here:

Are you perhaps mixing debug/release builds of the library and your application?

Are you perhaps building the app with a different compiler (even just different version) than SFML was built with?

Are you perhaps using a 8bit PNG image?

Have you tried specifying an absolute path to the image to load (to rule out CWD issues; although I believe we already did that - but still)?

PS. Imagemagick's identify command is great for getting details on images.
« Last Edit: July 03, 2015, 09:02:46 pm by Jesper Juhl »

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #11 on: July 03, 2015, 09:07:53 pm »
Jesper, Thanks for your continued assistance :

Quote
Are you perhaps mixing debug/release builds of the library and your application?

I double checked my lib input, it contains only the release versions:
sfml-graphics.lib
sfml-window.lib
sfml-system.lib

The particular project I'm creating right now is tiny enough right now (I'm literally just drawing/manipulating one sprite to check out the API before I start an honest project) that I'm just using the dll's.

Quote
Are you perhaps building the app with a different compiler (even just different version) than SFML was built with?

I'm using the pre-compiled Visual C++ 10 (2010) - 64-bit provided by the download on the home page. I'm using this IDE to build as well.

This weekend, I'll try just building from src myself and seeing what happens.


Quote
Are you perhaps using a 8bit PNG image?

Windows file properties reports the bit depth of the file is 32 bit.

Quote
Have you tried specifying an absolute path to the image to load (to rule out CWD issues; although I believe we already did that - but still)?

I tried using a string literal with the absolute path, but no dice.



Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: loadFromFile Failure
« Reply #12 on: July 03, 2015, 09:16:19 pm »
Jesper, Thanks for your continued assistance :
You're welcome.

Quote
Are you perhaps mixing debug/release builds of the library and your application?

I double checked my lib input, it contains only the release versions:
sfml-graphics.lib
sfml-window.lib
sfml-system.lib
But.. When I look at your previous posts I see many references to "Debug"??
That gets me thinking that perhaps you are building your app in debug mode and yet still linking it to the release mode SFML dll's - which would explain things behaving strangely...

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #13 on: July 03, 2015, 09:17:21 pm »
You're right, I derped right over that didn't I. Let me give it a whirl. I'll post back momentarily.

trashcanman980

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: loadFromFile Failure
« Reply #14 on: July 03, 2015, 09:19:58 pm »
Sadly, No change to behavior.