Strange problem concerning event managing

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Strange problem concerning event managing

Post by Peter Müller »

Hi there!
I've got a strange problem with my event managing. This is my CEventManager derivated from IEventReceiver:

Code: Select all

typedef irr::core::array vector;
Image



All events, which are received in OnEvent are saved in an Irrlicht Array.

Code: Select all

bool CEventManager::OnEvent(SEvent event)
{
 SEvent *evTmp = new SEvent;
 *evTmp = event;

 this->vLastEvents->push_back(evTmp);
 return false;
};


In my program's main loop, I check all events, saved in CEventManager::vLastEvents like this

Code: Select all

  vector<SEvent*> *vEvents = this->emEventManager->getLastEvents();
  for (unsigned int i = 0; i < vEvents->size(); ++i)
  {
   SEvent *evTmp = (*vEvents)[i];

   if ( (evTmp->EventType == EET_GUI_EVENT) && (evTmp->GUIEvent.Caller->getID() == this->buStarten->getID()) && (evTmp->GUIEvent.EventType == EGET_BUTTON_CLICKED) )
   {
    __LOG("[Spiel Starten]");
    bRun = false;
   }
  this->emEventManager->dropList();
The bRun variable is a bool, which describes, whether the loop should run or not. If it's false, the CGame object will be destroyed and new created (The device and the event receiver weren't destroyed, only the CGame object).
In the first run, everythink went perfect, the events were saved and evaluated. So if I press the button (IGUIButton buStarten), the CGame object will be destroyed and new created.
But in the second run the program crashes if I make a GUI Event (like pressing the button).

It crashes with this

Code: Select all

evTmp->GUIEvent.Caller->getID()
command. I think, the Caller pointer is wrong, but if I check this command in the OnEvent method everything is right?

Can somebody please help me and tell me, why this doesn't work or why the pointer is right in the OnEvent method of the CEventManager and wrong in the main loop of the CGame object?
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

Yes, your evTemp ptr seems to be bad.

One thing, why are you using an array? You should be using a queue, allows ordering events, etc.

Look up std::queue.
The Robomaniac
Project Head / Lead Programmer
Centaur Force
Guest

Post by Guest »

Are you sure your not dereferencing too far?

I'm not too fond of template code, so maybe I'm reading this wrong, but:

SEvent *evTmp = (*vEvents);

What you seem to be doing is create a pointer to an SEvent, and giving it the value of the i'th element of the first element of vEvents - is vEvents a list of pointers to arrays?
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

vEvents:

Code: Select all

vector<SEvent*> *vEvents = this->emEventManager->getLastEvents();
ah, now i understand, what you mean and yes, i create a pointer to an SEvent in which i write the value of vEvents

Code: Select all

SEvent *evTmp = (*vEvents)[i];
But the value is a pointer to an SEvent struct, so all should be right.
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Guest

Post by Guest »

OK.
Something else to check:
1. Where does the event manager object allocate the event array/queue? If it does not do that in the constructor, how does the method determine that a new event list has to be allocated?
2. If your dropList deallocates the array, does it do everything necessary to tell the other method that the array needs to be reallocated? (Like, for example, setting the lastevents pointer to NULL)
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

ah, got it!
It wasn't the array or the allocation, but I returned false in the OnEvent method, so the engine sended all events twize :roll:

Thanks a lot for your help, you and another guy helped my to find a resolution!
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
Post Reply