• Advertisement
Sign in to follow this  

A unhandled exception I can't handle. .

This topic is 4255 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
0 and I just set it as thus. So no change. :/

Share this post


Link to post
Share on other sites
First what language and/or API are you using? Because if it's Java I'm not understanding how you have a "global" variable. Also from what you posted I don't think that's the function giving you problems.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Looks like C++.

Share this post


Link to post
Share on other sites
My mistake it is deffined as -1. So I have to find out why its not changing.

Share this post


Link to post
Share on other sites
Do a search for your entire project for _iDragBall. Check each occurence for the possibility of where it can be assigned a value that is not valid.

Share this post


Link to post
Share on other sites
Not really related to your problem, but I think that both the 'signed' and the 'int' are uneccessary in your 'signed short int' cast, as every type of integer (except for 'char') is signed by default, and 'short' is an alias to 'short int'.

Share this post


Link to post
Share on other sites
Where do you have iDragball declared AND defined? is it used in multiple files? why is it initialized with -1 (is that you doing that or the compiler?) what compiler are you using? (if it's VC++ 6.0, THEN STOP AND DOWNLOAD VC++ 2005 EE)

answers to these questions and more at 11!

Share this post


Link to post
Share on other sites
Quote:
Original post by Dko
My mistake it is deffined as -1. So I have to find out why its not changing.


Presumably because the click didn't actually take place inside any of the golf ball sprites? :s

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by swiftcoder
...as every type of integer (except for 'char') is signed by default...


Can you back this up with fact? on every platform/compiler?

Share this post


Link to post
Share on other sites
Sorry for taking so long but yes I finnaly got it! Thanks every one. Right now Im not sure what I did (its late) but it worked. No more unhandled exception and at this point I have three golf balls moving around on my screen doing not tottaly what they should but close to it. Just gota work out some bugs(Like why the code to pick up the golf balls with the mouse doesn't work at all) and everything should be good. :P

Share this post


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

  • Advertisement