Skip to content

Commit 2bf69e3

Browse files
committed
Add notification to parents for parameterChanged when ofParameter<void> gets triggered. (openframeworks#6471)
1 parent 0d80969 commit 2bf69e3

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

libs/openFrameworks/types/ofParameter.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,50 @@ ofParameter<void>& ofParameter<void>::set(const std::string & name){
106106

107107
void ofParameter<void>::trigger(){
108108
ofNotifyEvent(obj->changedE,this);
109+
// Notify all parents, if there are any.
110+
if(!obj->parents.empty())
111+
{
112+
// Erase each invalid parent
113+
obj->parents.erase(std::remove_if(obj->parents.begin(),
114+
obj->parents.end(),
115+
[this](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
116+
obj->parents.end());
117+
118+
// notify all leftover (valid) parents of this object's changed value.
119+
// this can't happen in the same iterator as above, because a notified listener
120+
// might perform similar cleanups that would corrupt our iterator
121+
// (which appens for example if the listener calls getFirstParent on us)
122+
for(auto & parent: obj->parents){
123+
auto p = parent.lock();
124+
if(p){
125+
p->notifyParameterChanged(*this);
126+
}
127+
}
128+
}
109129
}
110130

111131
void ofParameter<void>::trigger(const void * sender){
112132
ofNotifyEvent(obj->changedE,sender);
133+
// Notify all parents, if there are any.
134+
if(!obj->parents.empty())
135+
{
136+
// Erase each invalid parent
137+
obj->parents.erase(std::remove_if(obj->parents.begin(),
138+
obj->parents.end(),
139+
[this](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
140+
obj->parents.end());
141+
142+
// notify all leftover (valid) parents of this object's changed value.
143+
// this can't happen in the same iterator as above, because a notified listener
144+
// might perform similar cleanups that would corrupt our iterator
145+
// (which appens for example if the listener calls getFirstParent on us)
146+
for(auto & parent: obj->parents){
147+
auto p = parent.lock();
148+
if(p){
149+
p->notifyParameterChanged(*this);
150+
}
151+
}
152+
}
113153
}
114154

115155
void ofParameter<void>::enableEvents(){

0 commit comments

Comments
 (0)