SFML community forums

Help => Graphics => Topic started by: trashcanman980 on July 03, 2015, 07:54:01 pm

Title: loadFromFile Failure
Post by: trashcanman980 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?
Title: Re: loadFromFile Failure
Post by: kitteh-warrior 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)?
Title: Re: loadFromFile Failure
Post by: Jesper Juhl 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.
Title: Re: loadFromFile Failure
Post by: trashcanman980 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.
Title: Re: loadFromFile Failure
Post by: Jesper Juhl 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 ;)
Title: AW: loadFromFile Failure
Post by: eXpl0it3r 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?
Title: Re: loadFromFile Failure
Post by: trashcanman980 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.
Title: Re: loadFromFile Failure
Post by: trashcanman980 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
Title: Re: loadFromFile Failure
Post by: Hapax 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
Title: Re: loadFromFile Failure
Post by: trashcanman980 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.
Title: Re: loadFromFile Failure
Post by: Jesper Juhl 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 (http://www.imagemagick.org/script/identify.php) command is great for getting details on images.
Title: Re: loadFromFile Failure
Post by: trashcanman980 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.


Title: Re: loadFromFile Failure
Post by: Jesper Juhl 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...
Title: Re: loadFromFile Failure
Post by: trashcanman980 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.
Title: Re: loadFromFile Failure
Post by: trashcanman980 on July 03, 2015, 09:19:58 pm
Sadly, No change to behavior.
Title: Re: loadFromFile Failure
Post by: Jesper Juhl on July 03, 2015, 09:22:49 pm
Ok, this is getting weird.
Could you post a complete minimal example program that I can test on my own machine (you almost already did, but I just want to be sure I run your exact code, not something where I've filled in the blanks)?
Title: Re: loadFromFile Failure
Post by: trashcanman980 on July 03, 2015, 09:24:01 pm
No, I take it back. I mistakenly forgot to to alter the literal with respect to the new executable location.

Thanks a ton Jesper, you've been a godsend.
Title: Re: loadFromFile Failure
Post by: Jesper Juhl on July 03, 2015, 09:25:52 pm
Ok, so it was a release/debug mixup after all. Good to know.

Glad I could help.
Enjoy SFML :)