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

Author Topic: Image LoadFromFile with strings problem.  (Read 2698 times)

0 Members and 3 Guests are viewing this topic.

drakelord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Image LoadFromFile with strings problem.
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Image LoadFromFile with strings problem.
« Reply #1 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.
Laurent Gomila - SFML developer

drakelord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Image LoadFromFile with strings problem.
« Reply #2 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

Antidote

  • Newbie
  • *
  • Posts: 35
    • View Profile
Image LoadFromFile with strings problem.
« Reply #3 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.

drakelord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Image LoadFromFile with strings problem.
« Reply #4 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.

 

anything