Page 1 of 1

Exception thrown after calling removeEvent()

Posted: Sun Mar 30, 2008 11:54
by HexDump
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.

Posted: Sun Mar 30, 2008 18:20
by CrazyEddie
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.

Posted: Mon Mar 31, 2008 14:45
by HexDump
heheeh, thanks mate.

HexDump.