Access Violation error

I'm having a problem understanding a particular error that is crashing a programing I'm trying to fix.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool Enemy::CheckCollision(ICollidable* pOtherObject)
{
	// Get the information about the other object
	float OtherPositionXY[2];
	pOtherObject->GetPosition(OtherPositionXY);
	float OtherSize = pOtherObject->GetCollisionSize();

	// Get the distance between the two objects
	float Difference[2] =
	{
		m_Position[0] - OtherPositionXY[0],
		m_Position[1] - OtherPositionXY[1]
	};
	float Distance = sqrtf((Difference[0] * Difference[0]) + (Difference[1] * Difference[1]));
	return (Distance < 0.5f * (OtherSize + k_EnemySize));
}


The access violation occurs on line 5 of the code. I understand that access violations are generally when pointers are pointing to something that they shouldn't and I think that is the case here. However, I'm still pretty new to C++ and I don't know how to proceed to find the origin of the error or how to fix it.

I should note that this is for a placement test and so if possible I'm not looking for a "cheat" I'm just stuck as to how to look for the cause of such an error.

Any help anyone can give is most welcome, thank you in advance.
Look where you call CheckCollision and try to see if you pass in a valid pointer.
1
2
float OtherPositionXY[2]; //this may be problem IS IT INITIALIZED?
pOtherObject->GetPosition(OtherPositionXY);
I've tried initialising OtherPositionXY and I get the same problem. I've also tried initialising pOtherObject by making it point to NULL and that just gives the same error but at 0x00000000 instead.
Topic archived. No new replies allowed.