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

Author Topic: White Square Problem - Please Help!  (Read 1309 times)

0 Members and 1 Guest are viewing this topic.

Kov

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
White Square Problem - Please Help!
« on: August 21, 2014, 07:54:30 am »
Hi,
I am having a lot of trouble with this and don't understand why I am getting the white square problem.

I have a class that handles all my assets (including textures) called CAssetManager and I use it by calling a function called LoadTexture(int id, std::string file) which loads the texture into a std::map<int, sf::Texture>. Then when I create a sprite, I set the texture of the sprite using a function called GetTexture(int id). This gives me a white square at the textures size.

Please Help!!

Here is my (reduced) CAssetManager.h code:
public:
void LoadTexture(int id, std::string file);
sf::Texture GetTexture(int id);
private:
std::map<int, sf::Texture> textureMap;
 

Here is my (reduced) CAssetManager.cpp code:
void CAssetManager::LoadTexture(int id, std::string file)
{
textureMap[id].loadFromFile(file);
}
sf::Texture CAssetManager::GetTexture(int id)
{
return textureMap[id];
}
 

Here is my (reduced) CMain.h code:
public:
CMain();
private:
sf::Sprite sprite;
CAssetManager asset;
 

And finally, here is my (reduced) CMain.cpp code:
CMain::CMain()
{
asset.LoadTexture(0, "test.png");
sprite.setTexture(asset.GetTexture(0));
}
 

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: White Square Problem - Please Help!
« Reply #1 on: August 21, 2014, 07:59:07 am »
At first glance, my guess is that you're not using any pointers or references, so you're copying the Textures and the copies get destroyed at the ends of functions using them.

I believe Thor has a ResourceManager class that might save you some of these headaches.

Kov

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: White Square Problem - Please Help!
« Reply #2 on: August 21, 2014, 08:03:14 am »
Yea I don't use references or pointers because I never could get my head around them when I was learning c++. Do you know any good sources or books that could explain them to me?

Thanks for the reply.

EDIT: I have found the Website on Thor's Resource Manager and will give it a read.
« Last Edit: August 21, 2014, 08:07:22 am by Kov »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email

Kov

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: White Square Problem - Please Help!
« Reply #4 on: August 21, 2014, 08:13:39 am »
Alright sweet thanks a ton! I shall buy one of those books and read it. I think I may have learnt c++ off one of those "Bad" books. :P

 

anything