Page 1 of 1

some really obscure error..

Posted: November 22nd, 2014, 5:59 pm
by Clodi

Code: Select all

Run-Time Check Failure #2 - Stack around the variable 'lattice' was corrupted.

Code: Select all

int main()
{
	Site site;


	return 0;
}

Code: Select all

class Site
{
private:
	float position[ NDIMENSIONS ];
	int neighbours[ NNEIGHBOURS ];
	float neighboursPosition[ NNEIGHBOURS ][ NDIMENSIONS ];

public:
	Site();
	Site( float,float,float );
};
and

Code: Select all

Site::Site()
{
	//initialise position
	for( int i = 0; i < NDIMENSIONS; i++ ) { position[ i ] = 0.; }

	//initialise neighbours
	for( int i = 0; i < NNEIGHBOURS; i++ ) { neighbours[ i ] = NSITES; }

	//initialise neighbours position
	for( int i = 0; i < NNEIGHBOURS; i++ )
	{
		for( int j = 0; j < NDIMENSIONS + 1; j++ )
		{
			neighboursPosition[ i ][ j ] = 0.;
		}
	}
}
The program crashes sometimes, and sometimes it doesn't. When it does, it writes that above. It's the same error that has been around for so long, but because I was using CodeBlocks I had no idea what it was..

Any help would be greatly appreciated.

Thanks,
Clodi :D

Re: some really obscure error..

Posted: November 22nd, 2014, 6:04 pm
by Clodi
the code breaks at the very end..
if I put a "cin >> a" type thing, the code will wait for me to enter a variable and then it will crash at the very end.

I tried adding a destructor and it didn't work.

Re: some really obscure error..

Posted: November 22nd, 2014, 6:21 pm
by LuisR14
i think this is wrong

Code: Select all

      for( int j = 0; j < NDIMENSIONS + 1; j++ )
don't you mean "j < NDIMENSIONS;" ?

Re: some really obscure error..

Posted: November 22nd, 2014, 9:15 pm
by Clodi
..! yes.. that's right. I had to add 1 at the very first stage, then I thought it would be confusing so I changed some of the code and forgot about that one 1 there.. grrrr

Thank you so much, Luis! :)

Re: some really obscure error..

Posted: November 22nd, 2014, 11:14 pm
by LuisR14
haha, no prob xD

Re: some really obscure error..

Posted: November 26th, 2014, 4:35 pm
by BurakCanik
Luis to the rescue as always :D