Well, I'm out of ideas for what could be going wrong. It crashes after calling setCellPendingAction in board.cpp more than once. Specifically, commenting out the line "liveNeighbors += 1" prevents the crash.
#include <stdlib.h> //Pure C random numbers for simplicity's sake, not used yet
#include <cstring> //strcat
#include <curses.h> //PDCurses. initscr, getmaxyx, printw
#include "board.h"
//using namespace std;
int main()
{
//cout << "Beginning curses mode" << endl;
initscr();
cbreak();
noecho();
printw("Entered curses mode\n");
refresh();
int sizex;
int sizey;
getmaxyx(stdscr, sizey, sizex);
char strbutts[10];
printw(strcat(itoa(sizex, strbutts, 10), "\n"));
printw(strcat(itoa(sizey, strbutts, 10), "\n"));
refresh();
printw("Allocating board memory\n");
refresh();
board mainBoard(sizex, sizey);
printw("Board allocated\n");
refresh();
int x;
int y;
for(x = 0; x < sizex; x++)
{
for(y = 0; y < sizey; y++)
{
if((rand() % 2) == 1)
{
mainBoard.boardArray[x][y].alive = true;
}
else
{
mainBoard.boardArray[x][y].alive = false;
}
}
}
char inp = getch();
while(getch() != -1)
{
mainBoard.setAllPendingActions();
inp = getch();
refresh();
}
return 0;
}
#include "board.h"
#include "cell.h"
#include <curses.h>
#include <cstring>
// Handling a two-dimensional array of cells
using namespace std;
//ctor
board::board(int rows, int cols)
{
boardArray = new cell*[rows];
boardRows = rows;
boardCols = cols;
int i;
for(i=0; i < boardRows; i++)
{
boardArray[i] = new cell[boardCols];
}
};
//dtor
board::~board()
{
int i;
for(i = boardRows; i > 0; i--)
{
delete[] boardArray[i];
}
delete[] boardArray;
};
void board::setAllPendingActions()
{
int x=0;
int y=0;
// As x goes up it goes across the columns
for(x = 0; x < boardCols; x++)
{
// As y goes up it goes down the rows
for(y = 0; y < boardRows; y++)
{
setCellPendingAction(x, y);
}
}
};
void board::setCellPendingAction(int x, int y)
{
short liveNeighbors = 0;
short i = 0;
short j = 0;
for(i = x-1; i <= x+1; i++)
{
for(j = y-1; j <= y+1; i++)
{
if(i < boardRows && j < boardCols)
{
if(boardArray[i][j].alive)
{
liveNeighbors += 1;
}
}
}
}
if(liveNeighbors < 2 || liveNeighbors > 3)
{
boardArray[x][y].setPendingAction(cell::BECOME_DEAD);
}
else
{
boardArray[x][y].setPendingAction(cell::BECOME_ALIVE);
}
};
void board::updateCells()
{
int x;
int y;
for(x = 0; x < boardCols; x++)
{
// As y goes up it goes down the rows
for(y = 0; y < boardRows; y++)
{
boardArray[x][y].update();
}
}
}
#include "cell.h"
void cell::setPendingAction(cellAction action)
{
pendingAction = action;
};
void cell::update()
{
if(pendingAction = BECOME_ALIVE)
{
alive = true;
}
else
{
alive = false;
}
}