Skip to content

ofParameter<void> notification loop #6602

Open
@eduardfrigola

Description

@eduardfrigola

Hello everyone.

I'm in a situation where I create ofParameters with .:newReference() function.
With that I have both ofParameters "linked together" similar to @arturoc ofParameterLink proposal

I have no issues with that except with ofParameter, as there is no notification loop safeguard.
I've resolved this issue updating what I did in this change with the notifiy loop safeguard implemented in :

inline void ofParameter<ParameterType>::eventsSetValue(const ParameterType & v){
// If the object is notifying its parents, just set the value without triggering an event.
if(obj->bInNotify)
{
noEventsSetValue(v);
}
else
{
// Mark the object as in its notification loop.
obj->bInNotify = true;
// Set the value.
obj->value = v;
// Notify any local subscribers.
ofNotifyEvent(obj->changedE,obj->value,this);
// Notify all parents, if there are any.
if(!obj->parents.empty())
{
// Erase each invalid parent
obj->parents.erase(std::remove_if(obj->parents.begin(),
obj->parents.end(),
[this](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
obj->parents.end());
// notify all leftover (valid) parents of this object's changed value.
// this can't happen in the same iterator as above, because a notified listener
// might perform similar cleanups that would corrupt our iterator
// (which appens for example if the listener calls getFirstParent on us)
for(auto & parent: obj->parents){
auto p = parent.lock();
if(p){
p->notifyParameterChanged(*this);
}
}
}
obj->bInNotify = false;
}
}

See implementation in: PlaymodesStudio@7bbf058

My doubt is about using this approach, or using the setMethod / eventsSetValue / noEventsSetValue. Seems as a more elegant solution but, as ofParameter has no value, its use is only for triggering events noEventsSetValue is not a needed function.

What do you think about that?

Thanks!
Eduard

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions