oFx:使用mouseEvent初始化类实例

时间:2018-06-25 10:30:23

标签: c++ exc-bad-access openframeworks

如果我运行此代码,它将给我Thread 1: EXC_BAD_ACCESS

topNav.h文件中:

 vector<indicatorButton> indicators;

topNav.cpp文件

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 );
    }



}

,然后在indicatorButton.cpp文件中:

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. 


}

如果我移除ofRegisterMouseEvents(),它将运行正常。除了我不注册鼠标事件:/

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

指针! 需要更改此内容:

 vector<indicatorButton> indicators;

对此

 vector<indicatorButton *> indicators;