In ofEvent.h
inline void notify(const void* sender, T & param){
if(ofEvent<T,Mutex>::enabled && !ofEvent<T,Mutex>::functions.empty()){
std::vector<of::priv::Function<T>*> functions_copy;
{
std::unique_lock<Mutex> lck(ofEvent<T,Mutex>::mtx);
std::transform(ofEvent<T,Mutex>::functions.begin(), ofEvent<T,Mutex>::functions.end(),
std::back_inserter(functions_copy),
[&](of::priv::Function<T>&f){return &f;});
}
for(auto & f: functions_copy){
if(f->function(sender,param)){
throw ofEventAttendedException();
}
}
}
}
this will be called every frame,so functions are copyed time and again(functions_copy) ,i think this is low efficient!!
Anyone can tell me why do this?
another problem I encountered with this,if i remove listener in the "f->function(sender,param)",and remove event will be called,and functions remove function,but in notify,it has no change(functions not remove the function),and it will crash!!
does “std::unique_lock lck(ofEvent::mtx);” really make any effects?
----------
some code:
in ofApp:
void ofApp::touchUp(ofTouchEventArgs & touch){
test->testRemoveListener();
}
in Test:
void Test::testRemoveListener(){
ofRemoveListener(ofEvents().touchUp, this, &Test::onTouchUp);
}
(already added listener)
-------------------
in old version:
template <class EventType,typename ArgumentsType, class ListenerClass>
void ofRemoveListener(EventType & event, ListenerClass * listener, void (ListenerClass::*listenerMethod)(ArgumentsType&), int prio=OF_EVENT_ORDER_AFTER_APP){
event -= Poco::priorityDelegate(listener, listenerMethod, prio);
}
if do like this,it will not crash.
this version is of_v0.9.0RC1_ios_release
PS: this crash not occur in draw/update(ofRemoveListener(ofEvents().draw, this, &Test::onDraw); )
-----
any ideas?