Exception thrown after calling removeEvent()

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

HexDump
Just popping in
Just popping in
Posts: 19
Joined: Fri Mar 07, 2008 11:49

Exception thrown after calling removeEvent()

Postby HexDump » Sun Mar 30, 2008 11:54

Hi all,

I have a window that I attach a hidden event in runtime. This is the code I use for adding removing the event:

Code: Select all


template <class _T>
      void SetResultCallback(bool (_T::*function)(const EventArgs&), _T* pObj)
      {
         this->m_pWindow->subscribeEvent (CEGUI::FrameWindow::EventHidden, Event::Subscriber(function,pObj));
      }

void CYesNoDialog::RemoveResultCallback()
{
   this->m_pWindow->removeEvent(CEGUI::FrameWindow::EventHidden);
}


The problem is the following: I can attach a handler without problem and it works ok, but when I call RemoveResultCallback(), and later on I call m_pWindow->hide() wich trows an exception (This m_pWindow is the window I added and removed a handler for the hidden event) saying:

Expresion: map/set iterator not incrementable.

I can guess what's hapenning, but don´t know how to fix it, or if I´m not removing the event correctly.

Can anyone help here?

Thanks in advance,
HexDUmp.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Sun Mar 30, 2008 18:20

Hi,

That is not the correct way to unsubscribe from an event ;) What you're actually doing is completely removing the event object from the window.

When you subscribe you get returned a connection object, you can (and should!) use this to unsubscribe...

Code: Select all

...
using namespace CEGUI;

Event::Connection con = myButton->subscribeEvent("Clicked", &myHandler);
...
// some time later
...
con.disconnect();
...


I hope this gives you the idea ;)

CE.

HexDump
Just popping in
Just popping in
Posts: 19
Joined: Fri Mar 07, 2008 11:49

Postby HexDump » Mon Mar 31, 2008 14:45

heheeh, thanks mate.

HexDump.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 13 guests