I am using CEGUI (Wonderfull tool;) ) for a few month yet, and until now, I never cared about unsubscribing to events.
For the moment I am creating a custom widget (a carousel), that contains a ribbon, on which I can dynamically add some button.
I can clear the Carousel, which in turns delete the ribbon which contains the buttons, and add a new one.
The problem is that my program crash during this operation.
So I tried to clear my events subscription before deleting the object for which an event has been subscribed (Do I really need to do this indeed?)
I do like this, but it seems quite painfull. Is it the only solution?
Code: Select all
void Carousel::createNewRibbon()
{
WindowManager& wmgr = WindowManager::getSingleton();
m_ribbon= static_cast<Ribbon*>(wmgr.createWindow( "MyWidgets/Ribbon"));
m_ribbonEventConnection = m_ribbon->subscribeEvent(
Carousel::EventClicked,
Event::Subscriber(&Carousel::ribbonClickedEv, this));
}
And when I clear the ribbon, and add a new one, I do like this....
Code: Select all
void Carousel::clear()
{
if(m_ribbon)
{
if(m_ribbonEventConnection )m_ribbonEventConnection ->disconnect();
delete m_ribbon;
m_ribbon= NULL;
}
createNewRibbon(); //
}
Indeed, I would need to "unbind" (unsubscribe), each little button on by ribbon? It seems very complicated, because I need to store a "connection" for each little button?
- Are the connection automatticaly deleted, when objects are deleted?
- Shall we always remove by hand the connections, in order to keep good performances?
Thanx in advance for your help