I am not pretty sure if I should post this here.
Well another query for the day. A bit long post this time. Please bear with me and help me
I have a class called TEnt which basically defines a entity.
I have another class called Manager which sort of manages the entity. The manager is a singleton class which has the following members
Code:
/*! This is called from other classes to register the instance with the manager*/
void REGISTER_ENTITY_INSTANCE(TEnt& instance);
/*! Call the set entity call in each of the registered entities*/
void EntityCall(void);
/*! Calls a draw entity call to each of the registerdd entity*/
void drawEntities(void);
/*! Prints out a test message*/
void print();
private:
/*! A vector of TEnts*/
std::vector < TEnt* > m_ppTEntList;
///////////////////////////////////////////converting this into a singleton
////////////////////////////////////////////////////////////////////////////
private:
EntityManager(){;}
EntityManager(const EntityManager&){;}
EntityManager& operator= (const EntityManager&){;}
static EntityManager* m_pInstance;
static bool is_InstanceSet;
public:
static EntityManager* getPInstance();
~EntityManager()
{
is_InstanceSet=false;
}
I have a Screen class which displays all the entities on the screen and a LevelEditor class which initialises and registers the entities on to the entity manager.
My Level Editor Class has the following function
Code:
void LevelEditor::Init_Level(){
EntityManager* Manager=EntityManager::getPInstance();
Manager->REGISTER_ENTITY_INSTANCE(a);
}
The REGISTER_ENTITY_INSTANCE(a) pushes the address of the instance onto a vector.
Code:
m_ppTEntList.push_back(&instance);
and my screen class has this
Code:
//Init level
LevelEditor* Levels=new LevelEditor;
Levels->Init_Level();
//Init the Emanager
EntityManager* EManager=EntityManager::getPInstance();
This piece of code initialises the level and gets a instance of the Manager.
Now This is the error I am facing
When I call the print function in the screen class it works fine .
it says that a entity has been registered and that the size of the vector is now 1. But this is the piece of code that seems to go wrong and creates a SEGMENTATION fault.
Code:
vector<TEnt*>::iterator iter;
for (iter=m_ppTEntList.begin();iter!=m_ppTEntList.end();iter++)
{
(*iter)->my_entity_paint();
}
All I wanted to do was access every element of the vector and then call a function of each of the element.
Can any one point me to where I am wrong or any better way at all to how this can be done.