EXC_BAD_INSTRUCTION error on runtime using ofParameters and Listeners

#1

Hey guys,
i have a problem , which has to do with the Listeners and Parameters.

I uploaded it on github: https://github.com/lkwWalter/spaceLoop
The programm works with Track()-class which contains Dimension()-classes (3) and depending on layerNumber-parameter multiple Instances of Element().
I added the listeners to the parameters.
this error occures during runtime when I change the offset-parameter. ( After I changed the layerNumber parameter) Maybe does this happen, because the layer-Number creates multiple Instances of Element-class, who all have a Listener to the same parameter with this code?:

 trackDimension  = &_usedTrackDimension;
    trackDimension->offset.addListener(this, &ElementDimension::updatePosition);
   

Its hard for me to find the error because it is on a very basic level:


this is, how it looks like:

the malloc_error_break says:

vj_2Debug(15457,0x1011215c0) malloc: Heap corruption detected, free list is damaged at 0x600000c73180

***** Incorrect guard value: 4487423435645530496**

I hope you can help me with that,
thanks a lot!

#2

Try to change your vector<Track> tracks to vector<shared_ptr<Track>> tracks

I assume this is because ofParameter with event listener is not copy safe.

Edit
If you are comfortable with raw pointer, you can first try vector<Track*> tracks first and see if it solve the problem.