At the beginning, my program creates a structure and a class that contain a struct and two int variables.
#define fullwidth 200
#define fullheight 200
typedef struct tiles
{
unsigned char red, green, blue;
char* name;
}tiles;
class Units
{
public:
int X_Pos;
int Y_Pos;
tiles MapColour;
}
After that, in the main part, I create a 2-dimensional array to use tiles as RGB containers for display, and an array of object pointers to follow any changes in the declared objects.
int i, j;
tiles fieldd[fullwidth][fullheight];
Units* DetectorField[fullwidth][fullheight];
Units Objects[10];
After that (now in main()), I upload both of the arrays with valid values, avoiding issues about that.
for (j=0;j<fullheight;j++)
{
for (i=0;i<fullwidth;i++)
{
fieldd[i][j] = BASE;
DetectorField[i][j] = NULL;
}
}
Same with the objects + adding object memory adress for pointers to be able to identify them through DetectorField:
for (i=0; i<9;i++)
{
Objects[i].X_Pos = i+2; //just some values, not important yet
Objects[i].Y_Pos = 2*i+2;
DetectorField[Objects[i].X_Pos][Objects[i].Y_Pos] = &Objects[i];
}
Most certainly, this is okay yet. But the problem comes now! In the next piece of codes, I check every elements of DetectorField; if the chosen element isn't NULL yet (which obviously means that it can be only the memory adress of an object, since it couldn't get any other values - if I know well), then put the MapColour variable to the array of structures.
for (j=0;j<fullheight;j++)
{
for (i=0;i<fullwidth;i++)
{
if(DetectorField[i][j] != NULL)
{
fieldd[i][j] = DetectorField[i][j]->MapColour;
}
}
}
At this point, MSVC gives this error message when I try to run it: Unhandled exception at 0x00411ed7 in Fallen Star.exe: 0xC0000005: Access violation reading location 0xccccccdc.
What did I do wrong? The operation inside the condition seems OK for me. Is the problem the way I use fieldd maybe?
tileswithstd::string.iandjwhen the violation occurs?std::string, I get stack overflow. Anyway: even if I changefullheightand alsofullwidth1, it crashes.