EXC_BAD_INSTRUCTION error on runtime using ofParameters and Listeners

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!

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.

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

*late response
putted this project aside, but now I have a Déjà-vu on this issue. And it appears when I try creating some objects of classes. avoiding the heap. And yes, smartpointers are the solution. Thank you though.

1 Like