SFML community forums

Help => Graphics => Topic started by: drakelord on May 30, 2009, 08:16:23 am

Title: Image LoadFromFile with strings problem.
Post by: drakelord on May 30, 2009, 08:16:23 am
Mkay, so, interesting problem here.

Code: [Select]
sf::Image LoadScreenImage;
std::string test = "res\\title.png";
if(!LoadScreenImage.LoadFromFile(test));
FAILED_TO_GET_RESOURCE


Results in the program not being able to load the image and going down.


Code: [Select]
sf::Image LoadScreenImage;
if(!LoadScreenImage.LoadFromFile("res\\title.png"));
FAILED_TO_GET_RESOURCE


On the other hand, works fine.  It says right in the documentation that it wants a std::string, but when I pass it one versus manually typing it in, it doesn't work.  

How to fix?
Title: Image LoadFromFile with strings problem.
Post by: Laurent on May 30, 2009, 09:40:57 am
Well, this code is so straight-forward that I can't believe it makes a difference at runtime. It is exactly the same.

Can you show a complete and minimal example that reproduces the problem? It's it's that simple, the minimal code should be very short.
Title: Image LoadFromFile with strings problem.
Post by: drakelord on May 30, 2009, 06:06:05 pm
So, oddly enough, while getting ready to make and post a test page, I noticed the problem right in the code I posted.

   if(!LoadScreenImage.LoadFromFile(test));

That semicolon at the end somehow caused it to fail.  Noo idea how, but it did.  *Fails*

Thanks for the help though, =D
Title: Image LoadFromFile with strings problem.
Post by: Antidote on June 02, 2009, 07:42:42 pm
the semicolon is the Line Terminator (Saying the statements over and to execute the next line), therefore your statement will always return a resource error.
Title: Image LoadFromFile with strings problem.
Post by: drakelord on June 03, 2009, 11:54:41 am
Quote from: "Antidote"
the semicolon is the Line Terminator (Saying the statements over and to execute the next line), therefore your statement will always return a resource error.


But when I put the string in manually, even with the semi-colon, it still worked.  That was why I was confused.  The semi-colon should kill it both ways.