Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I'm writing a C++ project, that is performing some graphical trasnformations.
I'm using a GPA.h class to create and manage pixel-arrays and Grid.h to break a bigger picture into a grid of smaller GPA-class pictures.

The function Grid::forge binds a grid of multipple GPA arrays into a bigger one.

C#
GPA Forge()
	{
	GPA Result=GPA(xtotal,ytotal);
	for (int n=0;n<=X;n++){
	for (int m=0;m<=Y;m++){
	Result.Insert((*this)[n][m],0,0,n*xrange,m*yrange,xrange,yrange);
	}
	}
	return Result;
	}


It addresses the function, GPA::Insert

C#
void Insert (GPA Source,int xSource, int ySource,int xHere, int yHere, int xArea,int yArea)
{
for(int m=0;m<yArea;m++){
for(int n=0;n<xArea;n++){
(*this)[xHere+n][yHere+m]=Source[xSource+n][ySource+m];
}
}
}


However when I execute the program it breaks with a error on the following line

C#
(*this)[xHere+n][yHere+m]=Source[xSource+n][ySource+m];


on first execution. I also get a Unhandled exception: Access violation reading location. The members of (*this)[n][m] variable appear to be not initialized, even if the constructer was called and the varaible has been addressed before

Anyone got an idea why it happens?
Thanks in advance
Posted
Updated 11-Apr-12 5:05am
v2

Please do this thing.
Debug your application and when you come to the statement:
C++
Result.Insert((*this)[n][m],0,0,n*xrange,m*yrange,xrange,yrange);

check the value of this[n][m] ,
because that is what going as first argument to
C++
void Insert (GPA Source,int xSource, ....) 
and which in turn your are trying to access in the statement
C++
(*this)[xHere+n][yHere+m]=Source[xSource+n][ySource+m];
 
Share this answer
 
Comments
Y0UR 11-Apr-12 11:31am    
Tried, debug was showing the correct values in the Forge function and no/wrong values in the Insert one.

Adding a

GPA Source =(*this)[n][m];

line, solved the problem, but created another one, now the destructor gets called twice... and the program crashes
Lakamraju Raghuram 11-Apr-12 12:06pm    
then you have't solved. Isn't it?
At a guess there is a bug in your program. The only way to find out why your variables have not been initialised (properly) is to use the debugger on it.
 
Share this answer
 
Comments
Lakamraju Raghuram 11-Apr-12 11:19am    
Perfect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900