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

Author Topic: Failed to load image "". Reason : Unable to open f  (Read 12685 times)

0 Members and 1 Guest are viewing this topic.

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« on: November 05, 2011, 01:26:40 am »
... is the error message I get after I run my program. I've checked the paths, they are ok, copied the images from their folder into the root of the program, even changed them from JPG to PNG and nothing... same error message for each image that is being loaded. It worked before in an other program, which was not much different from this one in terms of classes and such.
Here is the code:

main.cpp:

Code: [Select]

#include <iostream>
#include "kareninacharacter.h"
#include "blocks.h"
#include "mappings.h"

#define NAME "To heaven with you"


using namespace std;

int main() {

sf::RenderWindow *pApplication = new sf::RenderWindow(sf::VideoMode::GetMode(0), NAME, sf::Style::Fullscreen);

Blocks *pBackground = new Blocks(PLACEHOLDER);

kareninaCharacter *pPlayableCharacter = new kareninaCharacter(PLAYABLE_CHARACTER);

sf::Shape Floor = sf::Shape::Rectangle(0, 4800, 5000, 5000, sf::Color(50, 50, 50, 0)); //replace with Blocks

bool running = pApplication->IsOpened();

while(running)
{
sf::Event Event;

while(pApplication->GetEvent(Event))
{
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
pApplication->Close();
}
}

pApplication->Clear();


pApplication->Draw(pBackground->getSprite());

pApplication->Draw(Floor);

pApplication->Draw(pPlayableCharacter->getSprite());

pApplication->Display();
}

return 0;
}



mappings.h:

Code: [Select]

#ifndef MAPPINGS_H_
#define MAPPINGS_H_

#define PLACEHOLDER "placeholder.png"
#define PLAYABLE_CHARACTER "pc.png"

#endif


Also, the Blocks and kareninaCharacter class are pretty much the same, except the latter one has a few more methods, but the process of loading images and sprites is the same and as in the tutorial:

Code: [Select]

Blocks(string imglocation)
{

this->imgLocation = imgLocation;
Image.LoadFromFile(imgLocation);

Sprite.SetImage(Image);

}


I am using Visual Studio 2010 on Win7 x64
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #1 on: November 05, 2011, 11:06:55 pm »
Bumping...
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Failed to load image "". Reason : Unable to open f
« Reply #2 on: November 06, 2011, 10:00:08 am »
The error message suggests that somehow your image filename is empty.
Laurent Gomila - SFML developer

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #3 on: November 06, 2011, 08:01:43 pm »
Quote from: "Laurent"
The error message suggests that somehow your image filename is empty.


The only difference between this program and the program that worked, is that this program uses images created by myself, and the other one used images from the internet.
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Failed to load image "". Reason : Unable to open f
« Reply #4 on: November 06, 2011, 08:02:38 pm »
Can you provide a complete and minimal example that reproduces the problem?
Laurent Gomila - SFML developer

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #5 on: November 06, 2011, 08:25:27 pm »
Quote from: "Laurent"
Can you provide a complete and minimal example that reproduces the problem?


I'll post the whole code, without obfuscation:

main.cpp:
Code: [Select]

/*
 * main.cpp
 *
 *  Created on: Oct 21, 2011
 *      Author: scarborough
 *
 *
 * --------------------STATUS--------------------
 *
 * 444 - release
 * 333 - final testing
 * 222 - beta
 * 111 - alpha
 * 000 - pre-alpha
 *
 * ----------------------------------------------
 */

#include <iostream>
#include "kareninacharacter.h"
#include "blocks.h"
#include "mappings.h"

#define NAME "To heaven with you"

#define REVISION 0002
#define DATE_REVISION 05112011 //date of last increment to the REVISION macro
#define STATUS 000
#define DATE_STATUS 21102011 //date of last increment to the STATUS macro

using namespace std;

int main() {

sf::RenderWindow *pApplication = new sf::RenderWindow(sf::VideoMode::GetMode(0), NAME, sf::Style::Fullscreen);

Blocks *pBackground = new Blocks(PLACEHOLDER);

Blocks *pLevelBlock = new Blocks(BLOCK_LEVEL_X);

kareninaCharacter *pPlayableCharacter = new kareninaCharacter(PLAYABLE_CHARACTER);

sf::Shape Floor = sf::Shape::Rectangle(0, 4800, 5000, 5000, sf::Color(50, 50, 50, 0)); //replace with Blocks

bool running = pApplication->IsOpened();

while(running)
{
sf::Event Event;

while(pApplication->GetEvent(Event))
{
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
pApplication->Close();
}
}

pApplication->Clear();


pApplication->Draw(pBackground->getSprite());

pApplication->Draw(Floor);

pApplication->Draw(pPlayableCharacter->getSprite());

pApplication->Draw(pLevelBlock->getSprite());

pApplication->Display();
}

return 0;
}


mappings.h
Code: [Select]

/*
 * mappings.h
 *
 *  Created on: Aug 11, 2011
 *      Author: scarborough
 *
 */

#ifndef MAPPINGS_H_
#define MAPPINGS_H_

#define PLACEHOLDER "placeholder.png"
#define PLAYABLE_CHARACTER "pc.png"
/*
#define BLOCK_LEVEL_X ""
#define BLOCK_LEVEL_1 ""
#define BLOCK_LEVEL_2 ""
#define BLOCK_LEVEL_3 ""
#define BLOCK_LEVEL_4 ""
#define BLOCK_LEVEL_5 ""
#define BLOCK_LEVEL_6 ""
#define BLOCK_LEVEL_7 ""
#define BLOCK_LEVEL_8 ""
#define BLOCK_LEVEL_9 ""
*/
#endif


blocks.h:
Code: [Select]

/*
 * blocks.h
 *
 *  Created on: Aug 11, 2011
 *      Author: scarborough
 *
 */

#ifndef BLOCKS_H_
#define BLOCKS_H_

#include <iostream>
#include <SFML\Graphics.hpp>

using namespace std;

class Blocks{

public:

Blocks(string imglocation)
{

this->imgLocation = imgLocation;
Image.LoadFromFile(imgLocation);

Sprite.SetImage(Image);

}

virtual ~Blocks() {};

sf::Sprite getSprite();

private:

string imgLocation;
sf::Image Image;
sf::Sprite Sprite;
};

sf::Sprite Blocks::getSprite()
{
return Sprite;
}
#endif


kareninaCharacter.h:
Code: [Select]

/*
 * kareninacharacter.h
 *
 *  Created on: Aug 11, 2011
 *      Author: scarborough
 *
 */

#ifndef KARENINACHARACTER_H_
#define KARENINACHARACTER_H_

#include <iostream>
#include <SFML\Graphics.hpp>


using namespace std;

class kareninaCharacter {


public:

kareninaCharacter(string imglocation)
{

dead = false;

hostile = false;


health_bar = 100;

mana_bar = 100;


name = "Apoptygma";


attack_melee = false;

attack_ranged = false;


this->imgLocation = imgLocation;
Image.LoadFromFile(imgLocation);

Sprite.SetImage(Image);

};

virtual ~kareninaCharacter() {};


/* getters */

string getName() const;

bool getAttack_melee() const;

bool getAttack_ranged() const;


bool getDead() const;

bool getHostile() const;


short signed int getHealth_bar() const;

short signed int getMana_bar() const;

sf::Sprite getSprite() const;

/* setters */

void setName(string &name);

void setAttack_melee(bool &attack_melee);

void setAttack_ranged(bool &attack_ranged);


void setDead(bool &dead);

void setHostile(bool &hostile);


void setHealth_bar(short signed int &health_bar);

void setMana_bar(short signed int &mana_bar);

void setSprite(string imgLocation);


private:

/* identifiers */

string name;

bool attack_melee;

bool attack_ranged;



/* states */

bool dead;

bool hostile;


/* stats */

short signed int health_bar;

short signed int mana_bar;


/* technicalities */

sf::Sprite Sprite;
sf::Image Image;
string imgLocation;

};

/* getters */

string kareninaCharacter::getName() const
{
return name;
}

bool kareninaCharacter::getAttack_melee() const
{
return attack_melee;
}

bool kareninaCharacter::getAttack_ranged() const
{
return attack_ranged;
}


bool kareninaCharacter::getDead() const
{
return dead;
}

short signed int kareninaCharacter::getHealth_bar() const
{
return health_bar;
}

short signed int kareninaCharacter::getMana_bar() const
{
return mana_bar;
}

sf::Sprite kareninaCharacter::getSprite() const
{
return Sprite;
}

/* setters */

void kareninaCharacter::setName(string &name)
{
this->name = name;
}

void kareninaCharacter::setAttack_melee(bool &attack_melee)
{
this->attack_melee = attack_melee;
}

void kareninaCharacter::setAttack_ranged(bool &attack_ranged)
{
this->attack_ranged = attack_ranged;
}

void kareninaCharacter::setDead(bool &dead)
{
this->dead = dead;
}

void kareninaCharacter::setHostile(bool &hostile)
{
this->hostile = hostile;
}

void kareninaCharacter::setHealth_bar(short signed int &health_bar)
{
this->health_bar = health_bar;
}

void kareninaCharacter::setMana_bar(short signed int &mana_bar)
{
this->mana_bar = mana_bar;
}

void kareninaCharacter::setSprite(string imgLocation)
{
this->imgLocation = imgLocation;
Image.LoadFromFile(imgLocation);

Sprite.SetImage(Image);
}


#endif


I am running this with SFML 1.6
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #6 on: November 06, 2011, 08:31:58 pm »
And it works perfectly with this code:

main.cpp:
Code: [Select]

/*
SFMLTestum Testi: Exercise in SFML and HARDCORE OOP

Author: Milos Zivadinovic

Licence: if you are reading this expect Slenderman in your bathroom */


#include <SFML/Graphics.hpp>
#include <iostream>

#include "utilities.h"
#include "masterSprite.h"


int main()
{

sf::RenderWindow App(sf::VideoMode::GetMode(0), "I AM SLOWPOKE KING OF SLOW", sf::Style::Fullscreen);
App.UseVerticalSync(true);

bool running = App.IsOpened();


int width = App.GetWidth();
int height = App.GetHeight();


masterSprite *pSprite = new masterSprite("slowpoke.png");
/* masterSprite *pMegusta = new masterSprite("megusta.png");
masterSprite *pMudkip = new masterSprite("mudkip.png");
masterSprite *pWobbufet = new masterSprite("wobbufet.png"); */

const sf::Input &Input = App.GetInput();

std::cout << width << std::endl;
std::cout << height << std::endl;

bool indicator = true;

while (running)
{

sf::Event Event;


while(App.GetEvent(Event))
{
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::M))
{
if(indicator)
{
pSprite->setSprite("megusta.png");
indicator = false;
}

else
{
pSprite->setSprite("slowpoke.png");
indicator = true;
}

}


if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R))
{
utilities::r++;
(pSprite->Sprite).Rotate(utilities::r);
}

if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::T))
{
utilities::t++;
(pSprite->Sprite).SetRotation(utilities::t);
}


if(Event.Type == sf::Event::Closed)
{
running = false;
App.Close();
}

if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
running = false;
App.Close();
}


if(Input.IsKeyDown(sf::Key::Right))
{
utilities::x += utilities::speed;
if(utilities::x > width)
{
utilities::x = 0;
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}
else
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}

if(Input.IsKeyDown(sf::Key::Left))
{
utilities::x -= utilities::speed;
if(utilities::x < 0)
{
utilities::x = (float)width;
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}
else
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}

if(Input.IsKeyDown(sf::Key::Up))
{
utilities::y -= utilities::speed;
if(utilities::y < 0)
{
utilities::y = (float)height;
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}
else
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}

if(Input.IsKeyDown(sf::Key::Down))
{
utilities::y += utilities::speed;
if(utilities::y > height)
{
utilities::y = 0;
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}
(pSprite->Sprite).SetPosition(utilities::x,utilities::y);
}
}

App.Clear();

App.Draw(pSprite->Sprite);

App.Display();

}
return 0;

}


masterSprite.h:
Code: [Select]

/*
SFMLTestum Testi: Exercise in SFML and HARDCORE OOP

Author: Milos Zivadinovic

Licence: if you are reading this expect Slenderman in your bathroom */

#ifndef MASTERSPRITE_H_
#define MASTERSPRITE_H_

#include <iostream>
#include <SFML\Graphics.hpp>


class masterSprite
{

public:

masterSprite(std::string imgLocation);
~masterSprite() {};

sf::Sprite getSprite() const;

void setSprite(std::string imgLocation);

//variables
sf::Image Image;
std::string imgLocation;
sf::Sprite Sprite;
};

masterSprite::masterSprite(std::string imgLocation)
{
this->imgLocation = imgLocation;

Image.LoadFromFile(imgLocation);
Sprite.SetImage(Image);

}

sf::Sprite masterSprite::getSprite() const
{
return Sprite;
}

void masterSprite::setSprite(std::string imgLocation)
{
this->imgLocation = imgLocation;

Image.LoadFromFile(imgLocation);
Sprite.SetImage(Image);
}

#endif


utilities.h:
Code: [Select]

/*
SFMLTestum Testi: Exercise in SFML and HARDCORE OOP

Author: Milos Zivadinovic

Licence: if you are reading this expect Slenderman in your bathroom */
#ifndef UTILITIES_H_
#define UTILITIES_H_

namespace utilities
{

int speed = 10; //movement speed

float r = 0; //angle for incremental rotation
float t = 0; //angle for regular rotation

float x = 0; //x axis for movement
float y = 0; //y axis for movement

}

#endif
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?

sbroadfoot90

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #7 on: November 06, 2011, 10:24:43 pm »
Quote from: "praetoriaen"
Quote from: "Laurent"
Can you provide a complete and minimal example that reproduces the problem?


I'll post the whole code, without obfuscation:


He wanted less code, not more, keyword "minimal". Most of the time people don't have time to read through other people's code in details so you need to keep it brief if you have a chance of getting help.

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #8 on: November 06, 2011, 10:53:05 pm »
Quote from: "sbroadfoot90"
Quote from: "praetoriaen"
Quote from: "Laurent"
Can you provide a complete and minimal example that reproduces the problem?


I'll post the whole code, without obfuscation:


He wanted less code, not more, keyword "minimal". Most of the time people don't have time to read through other people's code in details so you need to keep it brief if you have a chance of getting help.


My bad, didn't read thoroughly :(

Regarding the code, it works in my second "non-obfuscated" post, but it fails to do so in the first one, even though the code is 99% the same... sorry, this is the most minimal I can to reproduce the bug :(
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Failed to load image "". Reason : Unable to open f
« Reply #9 on: November 06, 2011, 11:47:50 pm »
Quote
sorry, this is the most minimal I can to reproduce the bug

I don't think so ;)
The most minimal that you can do is a main that loads and play the sound. Then if it works (which is what I expect), focus on the 1% of your code that is different between both versions. That should produce another minimal code, that you can debug much more easily than your whole project. Etc, etc....

People just give up when they face a bug that they can't explain immediately, like if there was nothing to do. But it's your code, you wrote it, and you wrote the bug too, so there's always something you can do to find it and fix it -- with some extra work. Don't be afraid to write or remove code just for debugging.

And if you happen to find a really minimal code that still has the problem, then I'll be able to tell you whether it's a bug in SFML or not.

http://www.sfml-dev.org/forum/viewtopic.php?p=36368#36368
Laurent Gomila - SFML developer

praetoriaen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Failed to load image "". Reason : Unable to open f
« Reply #10 on: November 09, 2011, 10:50:40 pm »
Quote from: "Laurent"
Quote
sorry, this is the most minimal I can to reproduce the bug

I don't think so ;)
The most minimal that you can do is a main that loads and play the sound. Then if it works (which is what I expect), focus on the 1% of your code that is different between both versions. That should produce another minimal code, that you can debug much more easily than your whole project. Etc, etc....

People just give up when they face a bug that they can't explain immediately, like if there was nothing to do. But it's your code, you wrote it, and you wrote the bug too, so there's always something you can do to find it and fix it -- with some extra work. Don't be afraid to write or remove code just for debugging.

And if you happen to find a really minimal code that still has the problem, then I'll be able to tell you whether it's a bug in SFML or not.

http://www.sfml-dev.org/forum/viewtopic.php?p=36368#36368


I am sorry again for wasting your time. On the other hand, I think the problem is with Visual Studio 2010 project configurations... I'll just reset them and/or rebuild SFML
Through passion I gain strength
Through strength I gain power
Through power I gain victory
Through victory my chains are broken
--------------------------------------------
On a scale from bloat to enterprise, how does my code rank?