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

Author Topic: Image manager issues  (Read 1996 times)

0 Members and 3 Guests are viewing this topic.

Leodido

  • Newbie
  • *
  • Posts: 10
    • View Profile
Image manager issues
« on: March 12, 2010, 03:44:41 pm »
Hello all,

I just started using SFML and I'd like to make an image manager.

I used a vector to do so and everytime I try loading an image I get a return error saying it could not load image.

I'm 100% sure of my paths ;) (changed them of folder etc..)

I tried PNG, BMP and JPG with a simple image made in paint, same result.

Did I oversee something with my pointers?
Could it come from the fact I use a struct ?

Code: [Select]
struct SFML_Manager_Image
{
sf::Image Img;
sf::Sprite Sprite;
std::string FileName;
};


Code: [Select]
SFML_Manager_Errors SFML_Manager::LoadImageTest(const std::string &ImgFileName, unsigned int &ImgID)
{
SFML_Manager_Image *NewImageBuffer;
bool AlreadyLoaded = false, FuncResponse;
unsigned int LoadedIndex;
unsigned int iImgIndex;

// Create a new buffer and instance
NewImageBuffer = new SFML_Manager_Image;

// Check if the img file is already loaded
for(iImgIndex=0;iImgIndex > (SFML_Manager::ImageList.size() - 1);iImgIndex++)
{
if (SFML_Manager::ImageList[iImgIndex].FileName == ImgFileName)
{
AlreadyLoaded = true;
LoadedIndex = iImgIndex;
}
}

// Load image file?
if (!AlreadyLoaded)
{
FuncResponse = NewImageBuffer->Img.LoadFromFile(ImgFileName);
if (!FuncResponse)
{
   delete NewImageBuffer;
return Failure;
}

// Set the image on a sprite
NewImageBuffer->Sprite.SetImage(NewImageBuffer->Img);
}
else
{
// Set the image on a sprite
NewImageBuffer->Sprite.SetImage(SFML_Manager::ImageList[LoadedIndex].Img);
}

// Save File name
NewImageBuffer->FileName = ImgFileName;

// Return the sound Index
ImgID = SFML_Manager::ImageList.size() - 1;

return Success;
}
[/code]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image manager issues
« Reply #1 on: March 12, 2010, 04:13:34 pm »
There seems to be a lot of errors in this piece of code ;)
But let's first see whether your error is related to it or not.

Do you have the same error with this minimal code?
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::Image image;
    return image.LoadFromFile("your_image") ? 0 : -1;
}


What error message do you get on the standard error output (the console)?
Laurent Gomila - SFML developer

Leodido

  • Newbie
  • *
  • Posts: 10
    • View Profile
Image manager issues
« Reply #2 on: March 12, 2010, 04:23:26 pm »
j'avais pas vu que il y avais un site en Francais! Bonjour de la Suisse ;)

Anyway, the thing is nothing shows up as far as error messages are concerned on my console.

But the returned value is false.

I'm at home now and I don't have the tools installed yet, so I can't test this code yet.

Btw, can you tell me what other errors there are there please? thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image manager issues
« Reply #3 on: March 12, 2010, 05:19:35 pm »
Quote
Anyway, the thing is nothing shows up as far as error messages are concerned on my console.

But the returned value is false.

This is weird, every failure is supposed to come with an error message.

Quote
Btw, can you tell me what other errors there are there please? thank you!

Sure :)

* Looks like your > should be a < in:
Code: [Select]
for(iImgIndex=0;iImgIndex > (SFML_Manager::ImageList.size() - 1);iImgIndex++)
* ImageList is an array of SFML_Manager_Image but you create a SFML_Manager_Image*
* You never add NewImageBuffer to ImageList when you have to create a new one

In fact I don't understand how you handle your SFML_Manager_Image  instances. You start by creating a new one but then you search if it already exists in the array. Then you update some members of your new instance depending on whether you found it or not. And finally... the NewImageBuffer variable that you just created is lost in every case because you end up not using it, returning it or adding it to the array. Did I miss something? :)
Laurent Gomila - SFML developer

 

anything