Unhandled Exception Assertion Error

Started by
3 comments, last by rip-off 15 years, 4 months ago
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.pos.x = (80 * i) + 224;//the error occurs at this line.
	
		//y values
		m_brickList.pos.y = (384 - 100) - m_brickHeight;

		//z values
		m_brickList.pos.z = 0.0f;

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

		//VISIBILITY
		m_brickList.visible = true;
	}
}
Could my array have anything to do with the error? In the header, this is what it looks like: Brick m_brickList[10]; 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.
Advertisement
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.
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++)
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.
What is the type of m_brickList?

Using a standard container would mean you no longer need to manually keep count of the number of Brick instances.

This topic is closed to new replies.

Advertisement