I quite don't get it!
I've got a memory access violation on a perfectly normal code string. Error occurs when starting the application. I can click continiuse and everything goes on ok.
And more. If I enter a breakpoint before the bad line it doesn't stop there but the error is gone!
The function I'm referring to doesn't run on startup, it uses no pointers or smth. So as I told, I don't get it.
Can anyone help. Please!
int Field::GetCellX(int x, int y)
{
int i,ii,cx,cy;
double dist;
double mindist;
mindist=10000;
int CellX,CellY;
for (i=0;i<=(this->Picture->Width/(3*this->cellsize));i++)
for (ii=0;ii<=(this->Picture->Height/(4*this->cellsize));ii++)
{
cx=4*this->cellsize/2+i*3*this->cellsize;
cy=(((i%2)==0)?(4*this->cellsize/2+ii*4*this->cellsize):(4*this->cellsize+ii*4*this->cellsize));
dist=((cx-x)*(cx-x)+(cy-y)*(cy-y));
if (dist<mindist)
{
CellX=i;
CellY=ii;
mindist=dist; // !!!! THIS IS THE BAD LINE !!!!
};
}
return CellX+this->x;
};
Here is class declaration. Just in case...
class Field
{
public:
LivingCell *cell[GameSize*10];
FieldElement *point[GameSize][GameSize];
int density[6];
TImage *Picture;
int cellsize;
int x,y;
Field();
void DrawField();
int GetCellX(int x, int y);
int GetCellY(int x, int y);
void Spread(int, int, int);
void ClearAgents(void);
};