Search code examples
c++exc-bad-accessopenframeworks

oFx: initialising class instance with mouseEvent


If I run this Code it gives me a Thread 1: EXC_BAD_ACCESS.

in topNav.h file:

 vector<indicatorButton> indicators;

and in the topNav.cpp file

void topNav::setup(ofVec2f p, int n , int *appState) {

// ... other vars here
    for(int i = 1 ; i <= quantityOfPages ; i++){
        indicators[i-1].setup(i, ofVec2f(padding.x + spacing * i, padding.y ), appState );
    }



}

and in the indicatorButton.cpp file:

indicatorButton::indicatorButton() {
    bRegisteredEvents = false;
}

void indicatorButton::setup(int i, ofVec2f p, int *appState) {

    // this will enable our circle class to listen to the mouse events.
    if(!bRegisteredEvents) {
        ofRegisterMouseEvents(this);
        bRegisteredEvents = true;
    }

   // other variables...blah blah. 


}

If I remove the ofRegisterMouseEvents() it runs fine. except I don't register the mouse events :/

What am I doing wrong here?


Solution

  • Pointers! Needed to change this:

     vector<indicatorButton> indicators;
    

    to this

     vector<indicatorButton *> indicators;