2 次元のセルオートマトンを Processing から openFrameworks (C++) に変換しようとしています。私はセルとライフ ゲーム機能のクラスを作成しました。アプリケーションは正常にビルドされますが、次のエラーですぐにクラッシュします: スレッド 1: プログラムはシグナルを受け取りました: "EXC_BAD_ACCESS".
これが私のライフゲームクラスのヘッダーです
#include "Cell.h"
class GoL {
public:
GoL();
void init();
void generate();
void display();
void run();
int w = 20;
int cols;
int rows;
std::vector<vector<cell> > board;
};
実装は次のとおりです。
#include "GoL.h"
GoL::GoL() {
cols = ofGetWidth() / w;
rows = ofGetHeight() / w;
board[rows][cols];
init();
}
void GoL::run() {
generate();
display();
}
void GoL::init() {
for (int i = 0; i < cols; i ++) {
for (int j = 0; j < rows; j ++) {
board[i][j] = *new cell(i * w, j * w, w);
}
}
}
void GoL::generate() {
for (int i = 0; i < cols; i ++) {
for (int j = 0; j < rows; j ++) {
board[i][j].savePrevious();
}
}
for (int x = 0; x < cols; x ++) {
for (int y = 0; y < cols; y ++) {
int neighbours = 0;
for (int i = -1; i <= 1; i ++) {
for (int j = -1; j <= 1; j ++) {
neighbours += board[(x + i + cols) % cols][(y + j + rows) % rows].previous;
}
}
neighbours -= board[x][y].previous;
// Rules of Life
if ((board[x][y].state == 1) && (neighbours < 2)) board[x][y].newState(0);
else if ((board[x][y].state == 1) && (neighbours > 3)) board[x][y].newState(0);
else if ((board[x][y].state == 0) && (neighbours == 3)) board[x][y].newState(1);
}
}
}
void GoL::display() {
for (int i = 0; i < cols; i ++) {
for (int j = 0; j < rows; j ++) {
board[i][j].display();
}
}
}
エラーは、vector.h ファイル、GoL ヘッダー ファイル、および GoL 実装で init() メソッドを呼び出す場所に表示されます。どんな助けでも大歓迎です。