Sign in to follow this  
Firecore

Unhandled Exception Assertion Error

Recommended Posts

What does and unhandled exception and assertion error actually mean? In visual studio, when i run the game in debug mode, it always returns an unhandled exception access violation error at this part:
void CBrickManager::generateBallData()
{
	for(int i = 0; i = (m_numBricks - 1); i++)
	{
		//////////////////////////
		//ROW 1
		//////////////////////////

		//POS
		//x values
		
		
		m_brickList[i].pos.x = (80 * i) + 224;//the error occurs at this line.
	
		//y values
		m_brickList[i].pos.y = (384 - 100) - m_brickHeight;

		//z values
		m_brickList[i].pos.z = 0.0f;

		//VEL
		m_brickList[i].vel.x = 0.0f;
		m_brickList[i].vel.y = 0.0f;
		m_brickList[i].vel.z = 0.0f;

		//VISIBILITY
		m_brickList[i].visible = true;
	}
}
Could my array have anything to do with the error? In the header, this is what it looks like: [code] Brick m_brickList[10]; [code] Brick is a struct that holds data on the bricks:
struct Brick
{
	D3DXVECTOR3 pos;
	D3DXVECTOR3 vel;
	bool visible;

};
Could you guys help me out? I tried replacing the dot with '->' when i use an array, but then i just get compile errors.

Share this post


Link to post
Share on other sites
If I were to guess... I'd say that the line in question throws up an error because you are trying to access memory outside the boundaries of an array.

Anytime you are accessing arrays, make sure the index (i in your case) is between (0) and (maximum size of the array - 1)

I.e. check that m_numBricks actually equals the maximum size of the array (which according to your code is 10).

EDIT:

Also the line;

for(int i = 0; i = (m_numBricks - 1); i++)

looks strange to me. You've assigned i to 0, and then you keep on assigning it to m_numBricks - 1 during the entire loop.

Share this post


Link to post
Share on other sites
I looked at what you said about the value for m_numBricks.
originally, i had numBricks like this in the header file:

static const int m_numBricks = 10;


but i changed that to a normal int and tried initialising m_numBricks in the class constructor, but then then i started getting the same error at that line in the constructor.


CBrickManager::CBrickManager(void)
{
m_numBricks = 10;//this is where the error occured
generateBallData();
}



I also changed
for(int i = 0; i = (m_numBricks - 1); i++) to

for(int i = 0; i < (m_numBricks - 1); i++)

Share this post


Link to post
Share on other sites
Glad to see you've pinned down your error.

Believe it or not but tracking down errors and then fixing them is a vital part of getting to grips with programming... As long as one learns from their mistakes of course (and take it from me we ALL make them... Experts and novices alike!)

One last point... Your code:

for(int i = 0; i < (m_numBricks - 1); i++)

is still not quite 100%. Reason? You are now testing i to make sure it’s less than m_numBricks - 1 (i.e. 9 if m_numBricks = 10), when in fact you should be testing i to make sure it's less than m_numBricks.

re-writing your code to;

for(int i = 0; i <= (m_numBricks - 1); i++)

or

for(int i = 0; i < m_numBricks; i++)

should fix that problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this