I ran into a problem and I’m asking me if there is a bug or something else in OF’s Event System or if I’ve done bad things with ofEvents.
I’m generating many objects which are all created/destroyed like this:
Object::Object()
{
ofRegisterMouseEvents(this);
// ...
}
Object::~Object()
{
ofUnregisterMouseEvents(this);
// ...
}
Every object has all the methods like mouseDragged, mouseMoved, … .
All objects are stored in a vector called “objects” in my App. But if I’m running code like this
void Core::mousePressed(int x, int y, int button)
{
objects.erase(objects.begin(),objects.end()); //objects are deleted in this way because they are boost::shared_ptr's
}
my app crashes without error.
Debugging:
Points me to Delegate.h line 144
bool notify(const void*, TArgs& arguments)
{
(_receiverObject->*_receiverMethod)(arguments); // Line 144
return true; // a "standard" delegate never expires
}
#0 ( 0x000000000000038d in ??() (??:??)
#1 0x437a0a Poco::Delegate<ds::BaseNode, ofMouseEventArgs, false>::notify(this=0x97baf0, arguments=...) (../openFrameworks/libs/poco/include/Poco/Delegate.h:144)
#2 0x44b13d Poco::FIFOStrategy<ofMouseEventArgs, Poco::AbstractDelegate<ofMouseEventArgs>, Poco::p_less<Poco::AbstractDelegate<ofMouseEventArgs> > >::notify(this=0x957d70, sender=0x0, arguments=...) (../../../poco/include/Poco/FIFOStrategy.h:85)
#3 0x449223 Poco::AbstractEvent<ofMouseEventArgs, Poco::FIFOStrategy<ofMouseEventArgs, Poco::AbstractDelegate<ofMouseEventArgs>, Poco::p_less<Poco::AbstractDelegate<ofMouseEventArgs> > >, Poco::AbstractDelegate<ofMouseEventArgs>, Poco::FastMutex>::notify(this=0x86c518, pSender=0x0, args=...) (../../../poco/include/Poco/AbstractEvent.h:229)
#4 0x447587 ofNotifyEvent<ofEvent<ofMouseEventArgs>, ofMouseEventArgs>(event=..., args=...) (../../../openFrameworks/events/ofEventUtils.h:106)
#5 0x447002 ofNotifyMousePressed(x=422, y=296, button=0) (../../../openFrameworks/events/ofEvents.cpp:161)
#6 0x460f9c ofAppGlutWindow::mouse_cb(button=0, state=0, x=422, y=296) (../../../openFrameworks/app/ofAppGlutWindow.cpp:595)
#7 0x7ffff3c21716 glutMainLoopEvent() (/usr/lib/libglut.so.3:??)
#8 0x7ffff3c21b17 glutMainLoop() (/usr/lib/libglut.so.3:??)
#9 0x4608b6 ofAppGlutWindow::runAppViaInfiniteLoop(this=0x7fffffffe620, appPtr=0x956250) (../../../openFrameworks/app/ofAppGlutWindow.cpp:303)
#10 0x461a20 ofRunApp(OFSA=0x956250) (../../../openFrameworks/app/ofAppRunner.cpp:87)
#11 0x430c87 main() (src/main.cpp:16)
So is it because I’m destroying elements with Listeners just when I’m calling a listener?! Or is it totally dump to put ofRegisterMouseEvents(this); in every object?
thanks for your help!
ben