Jump to content
  • Advertisement
Sign in to follow this  
Dko

A unhandled exception I can't handle. .

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well right now let me put it blunty. Im confused as to what I have to do. Ive gotten my program to finnaly compile after adding in sprite handling code but now it raises an unhandled exception when this line of code is executed (At least I think so. Its where the program stops). Ive tried everything I could think of to figure out what is wrong but nothing seams to lead me in any concrete direction to whats wrong. Please I serously need help otherwise im going to rip out my brain with a spoon. >.<
void Sprite::SetPosition(int x, int y)
{
	
	m_rcPosition.x = (signed short int)x;
	m_rcPosition.y = (signed short int)y;
	
}
I get this when it runs. Unhandled exception at 0x0041351a in JPong.exe: 0xC0000005: Access violation writing location 0x00000008. There is probibly more information you need but im not sure what. If so just ask. Im tottaly stumped.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
What's your "this" pointer?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dko
Well right now let me put it blunty. Im confused as to what I have to do. Ive gotten my program to finnaly compile after adding in sprite handling code but now it raises an unhandled exception when this line of code is executed (At least I think so. Its where the program stops). Ive tried everything I could think of to figure out what is wrong but nothing seams to lead me in any concrete direction to whats wrong. Please I serously need help otherwise im going to rip out my brain with a spoon. >.<


void Sprite::SetPosition(int x, int y)
{

m_rcPosition.x = (signed short int)x;
m_rcPosition.y = (signed short int)y;

}



I get this when it runs.
Unhandled exception at 0x0041351a in JPong.exe: 0xC0000005: Access violation writing location 0x00000008.

There is probibly more information you need but im not sure what. If so just ask. Im tottaly stumped.


That exception code is one that indicates an access violation (you were accessing memory you don't own. Typically when this happens while accessing member variables it means you have not properly initialized an instance of your class. i.e:

struct Point {
float x;
float y;
};

Point* p;
p->x = 1.0f; //Access violation, 0xC0000005


Please see the most recent article to be published on debugging on this site: "Introduction to Debugging"

Share this post


Link to post
Share on other sites
uh not totally sure this will fix anything, but I think you might try casting in the arguements (or maybe called parameter):

void Sprite::SetPosition(signed short int x, signed short int y)

{



m_rcPosition.x = x;

m_rcPosition.y = y;



}

That might not fix anything though.

Share this post


Link to post
Share on other sites
Do you mean what the debugger shows for the 'this' pointer? I get this garbled mess. >.o
0x00000000 {m_pBitmap=??? m_rcPosition={...} m_ptVelocity={...} ...} Sprite * const
Which seams to mean its pointing to nothing?

Share this post


Link to post
Share on other sites
looks like a null pointer exception. It means that the pointer isn't pointing to an object.

eg
Sprite * pSprite = 0;
pSprite->SetPosition(0, 0);

should cause the same error.

Share this post


Link to post
Share on other sites
In other words, if you don't have:
Sprite playerSprite = new Sprite("bob"); //or however your constructor is


then you're gonna have problems. If that doesn't help, then post code. [smile]

Share this post


Link to post
Share on other sites
Okies I think im narrowing it down (Thanks a lot ^^). For some reason my global variable _iDragBall is saposta have a value from 0-2(the number of Sprites) but the value comes up to be -1. Thus making _pGolfBallSprite[_iDragBall]->SetPosition() referance a null area of memmory.

The thing is I don't see why _iDragBall would be -1. Any clues? Because this function looks innocent enough.


void MouseButtonDown(int x, int y, int iButton)
{
// See if a ball was clicked with the left mouse buttom

if (iButton == LEFT && !_bDragging)
{
for (int i = 0; i < 3; i++)
if (_pGolfBallSprite->IsPointInside(x,y))
{
// Capture the mouse
SetCapture(_pGame->GetWindow());

// Set the drag state and the drag ball
_bDragging = TRUE;
_iDragBall = i;

// Simulate a mouse move to get started
MouseMove(x, y);

// Don't check for more balls
break;
}
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!