Quantcast
Channel: bugs, errors - openFrameworks
Viewing all articles
Browse latest Browse all 636

Not all triggered ofEvents are being caught

$
0
0

@nununo wrote:

Hello,

I am experiencing a strange behaviour when using ofEvents.

An instance of class A contains a list of instances of class B (vector). At certain times each of these class B instances thrown a fork event which is caught by class A to create a new instance of B and add it to the list.

I started experiencing a strange behaviour: very few instances were being created compared to what I was expecting. Furthermore, in some scenarios, at some point A LOT of instances are created.

This led me to wonder if all triggered events were being executed and actually creating a new instance.

So I decided to:

  • create a public attribute in class A called total;
  • send the instance of class A into class B by passing this in class B’s constructor;
  • have class B directly increase that total each time it throws an ofEvent.

And what I found is that, as I suspected, the value in total greatly exceed the amount of B instances created. At some point total=13332 and _list.size()=6212. Which seems to show that good part of the events are not triggering the observer’s method A.onEvent().

Since I already had access to the observer instance A inside the instances B I decided to bypass the event and call A.onEvent() directly from classB. And indeed total = list.size().

I suspect that this maybe cause not by the amount of events being triggered but by the fact that there are thousands of B instances and instance A is listening to every single one of them. Still, I’d expect this to work in a reliable way.

Is this a bug or can it be something I’m doing wrongly? If so, any suggestions are welcome!

For now I’ll have to stop using ofEvents and call the Observer’s method directly from within the Subjects.

Here is the code at a commit in which this behaviour can be observed:
https://github.com/nununo/ofMoldApp/tree/7b7154804d3ec99ff84a2643631ae457e837e5d7

Subject class: Hypha
Observer class: Hyphae

Thank you,
Nuno

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 636

Trending Articles