Problem with events...

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

Nuker
Just popping in
Just popping in
Posts: 5
Joined: Sat Feb 11, 2006 19:56

Problem with events...

Postby Nuker » Sat Feb 11, 2006 20:31

Hi @ll

I have a serious problem with the events in CEGUI ... it is no problem to register new handlers for events but i can't unsubscribe them ... I tried everything and searched the whole forum but I didn't find a solution ...

Here's a the piece of code I use .. don't worry, this code is only for testing ;) ...

Code: Select all

// The eventName is always "MouseClick"

CEGUI::Event::ConnectionInterface* connection;

void thorGuiObject::SubscribeEvent( const char* eventName, const luabind::adl::object& luaFunc )
{
   connection = _targetWindow->subscribeEvent( eventName, CEGUI::Event::Subscriber( &thorGuiObject::HandleEvent, this )).get();
   LogManager::getSingleton().logMessage( "Subscribe" );
}

void thorGuiObject::UnsubscribeEvent( const char* eventName )
{
   connection->disconnect();
   
   //delete connection;

   LogManager::getSingleton().logMessage( "Unsubscribe" );
}

bool thorGuiObject::HandleEvent( const CEGUI::EventArgs& e )
{
   LogManager::getSingleton().logMessage( "Event handled" );

   UnsubscribeEvent( "MouseClick" );

   return true;
}


Everytime I want to unsubscribe I get an error message like this:

Image

I don't know what to ... what am i doing wrong?? Please help me...

C YA - []Nuker

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

Postby CrazyEddie » Sun Feb 12, 2006 10:58

Hi,

The actual type that you should be using to store connections is:

Code: Select all

CEGUI::Event::Connection


And you hold the actual object, not a pointer to it. In actual fact 'CEGUI::Event::Connection' is a kind of light-weight container for the actual internal connection object, and these containers can be copied, assigned, and passed around freely.

So basically you need this kind of thing:

Code: Select all

CEGUI::Event::Connection connection;

void thorGuiObject::SubscribeEvent( const char* eventName, const luabind::adl::object& luaFunc )
{
   connection = _targetWindow->subscribeEvent( eventName, CEGUI::Event::Subscriber( &thorGuiObject::HandleEvent, this )).get();
   LogManager::getSingleton().logMessage( "Subscribe" );
}

void thorGuiObject::UnsubscribeEvent( const char* eventName )
{
   connection.disconnect();

   LogManager::getSingleton().logMessage( "Unsubscribe" );
}

bool thorGuiObject::HandleEvent( const CEGUI::EventArgs& e )
{
   LogManager::getSingleton().logMessage( "Event handled" );

   UnsubscribeEvent( "MouseClick" );

   return true;
}


HTH

CE.

Nuker
Just popping in
Just popping in
Posts: 5
Joined: Sat Feb 11, 2006 19:56

Postby Nuker » Sun Feb 12, 2006 14:09

I tried it like you said but I get an compiler error

Code: Select all

connection.disconnect();

error C2039: 'disconnect' : is not a member of 'CEGUI::RefPtr<T>'
c:\projects\c++\thor\thorclient\thorclient\thorguiobject.cpp


I also tried

Code: Select all

connection.get()->disconnect();


But with this solution i get the same error message as shown in my first post.. but i'm using the latest (0.4.1) version of CEGUI ...

Strange...

C YA - []Nuker

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

Postby CrazyEddie » Sun Feb 12, 2006 15:59

Yeah, very sorry - my mistake :oops:

it should have been:

Code: Select all

connection->disconnect();


Even though connection is not a pointer type as such, as mentioned above it's a kind of container or "smart pointer", so the dereferencing operator is used.

CE.

Nuker
Just popping in
Just popping in
Posts: 5
Joined: Sat Feb 11, 2006 19:56

Postby Nuker » Mon Feb 13, 2006 15:48

Still the same ... i always get the assertion failure ...

:cry: :cry: :cry:

Nuker
Just popping in
Just popping in
Posts: 5
Joined: Sat Feb 11, 2006 19:56

Postby Nuker » Mon Feb 13, 2006 19:17

I played a bit around and now I think I know where there failure came from:

I tried to close the Connection while i was inside the EventHandler.
My EventHandler function triggered the Unsubscribtion function ...

Hm... I think I must implement something like a queue where all connections are stored which should be closed ... and run through this queue after finishing all EventHandler functions ...

Or is there already something like this in CEGUI ???

C YA - []Nuker

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

Postby CrazyEddie » Mon Feb 13, 2006 20:33

Yep, you're right. It's because the disconnection is done from within the event handler (that'll teach me to look more closely at the code you posted ;) ).

The issue has been raised before here, and a potential patch might be in the works here, though I'm not sure of the status of that effort.

So, basically, yeah, for now you'll need to implement some kind of pool to store the connections you need to erase and handle it outside of the event handlers :? .

CE.

Nuker
Just popping in
Just popping in
Posts: 5
Joined: Sat Feb 11, 2006 19:56

Postby Nuker » Tue Feb 14, 2006 06:38

Ok, at least I know where the failure comes from :) and I can solve the problem.

Thx for your help CE and THX(!!!) for your great gui system!!!

C YA - []Nuker


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 15 guests