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

Author Topic: LoadFromFile issues in VS2012  (Read 3176 times)

0 Members and 1 Guest are viewing this topic.

BigZiggityZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
LoadFromFile issues in VS2012
« on: May 11, 2013, 09:34:24 pm »
Hello,

Whenever I try to call LoadFromFile, all I get is a message in the console that says 'failed to load "texture.png' followed by a long stream of gibberish, without ever closing the quote marks on texture.png. In addition, I get a seemingly random sequence of beeps coming out of my speakers. While reading I found that this can be a result of trying to access a file that does not exist, but the error still happens when I write out the full file path, e.g. "C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\Debug\ball.jpg". I am completely lost and hoping someone can offer some insight.

Code:

#include<SFML\graphics.hpp>
using namespace sf;

int main()
{
    Texture myText;
        if (!myText.loadFromFile("Ball.jpg"))
        {
                return 1;
        }
    return 0;
}
 

Where Ball.jpg is in the directory "C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\Debug" and "C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\SFML Game1"

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: LoadFromFile issues in VS2012
« Reply #1 on: May 12, 2013, 01:21:21 am »
When running from Visual Studio the resource needs to be in the directory of the project file. To go around it, go to Project Settings -> Debugging and change the Working Directory to something else.


lrx

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: LoadFromFile issues in VS2012
« Reply #2 on: May 12, 2013, 04:04:13 am »
"C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\Debug\ball.jpg"
probably wouldn't work because \ is escape character that should be escaped in path string...

in Visual Studio 2012 they've changed search directories, for example if you have something like this:

[solution catalog]
{
   [Debug]
   {
          (debug Dll Files and Exe outputs)
   }
   [Release]
   {
          (release Dll Files and Exe outputs)
   }
   [Project catalog]
   {
          (headers)
          (cpp)
          (resources loaded by your programs - images, fonts)
    }
    (Solution files)
}


Legend:
[catalog name]
{
    catalog content
}

(file/files)

BigZiggityZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: LoadFromFile issues in VS2012
« Reply #3 on: May 12, 2013, 04:20:24 am »
Thanks for the quick replies!

"C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\Debug\ball.jpg"
probably wouldn't work because \ is escape character that should be escaped in path string.

Whoops, forgot to mention that I was using escape sequences when I tried the above method. Also, this is just out of desperation to make it work, I know I can't hard code in a directory.

I have my image in the same folder as my .cpp file, the Visual Studio project files, and the debug folder. It also exists in the output folder with the .exe. I still can't see what I'm doing wrong.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: LoadFromFile issues in VS2012
« Reply #4 on: May 12, 2013, 06:51:36 am »
Not sure if this has anything to do with it, just thought I'd mention it just in case though.

In the code you posted you try to load a Ball.jpg, then later say you try giving it the full path with is "C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\Debug\ball.jpg" but assure us that Ball.jpg exists in this directory.

If you give it a full path, that should work. Is it possible you name it the wrong thing on accident?
DSFML - SFML for the D Programming Language.

 

anything