Public Group

# Unhandled Exception Error

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

## Recommended Posts

I am getting a strange error on a seemingly simple line of code. There is a class that holds 'bool W', and functions getW() {return W;}; and setW(bool w) { W = w; }; as members of this class. DirectInput checks all the keys and uses setW(true) if the W key is pressed, and setW(false) otherwise. Another function calls getW() to see if the W key is pressed or not, and when it does, the program crashes with "Unhandled exception at 0x00428326 in project0.exe: 0xC0000005: Access violation reading location 0xcdcdcded." pointing to the line getW() {return W;}; . What is going on?

##### Share on other sites
An error like this has happened to me recently. My problem was that I had a pointer to my class, and the pointer to that class was invalid (It may have been NULL or not initialized I can't remember) but when I attempted to access a method of that class I got a similar exception. Are you using a pointer to an instance of that class which may be invalid?

EDIT:
Here's some code that illustrates this point:

class MyClass{private:	bool W;public:	void setW(bool w) { W = w; }	bool getW() const { return W; }};int main(){	MyClass *pClass = NULL; 	bool w = pClass->getW(); // Attempting to dereference an invalid pointer!!!	return 0;}

##### Share on other sites
The error that you're getting is actually "0xC0000005: Access violation"

0xcdcdcded is 32 bytes away from 0xCDCDCDCD

C++ Q&A

Quote:
 0xCDCDCDCD is a debugging value that comes from the bowels of the C runtime library. When you allocate a block of memory in a debug build, it's initialized to this spurious value in the hope of catching bugs. 0xCDCDCDCD is non-NULL and is never a valid memory pointer.

So it appears that you have a block of allocated memory that's supposed to contain a pointer but was never assigned a valid address and that you added 32 to that pointer and then tried to dereference it.

##### Share on other sites
As LessBread says, this is you dereferencing an invalid pointer:
myClassPtr->getW();

myClassPtr is invalid (as indicated by the fact that it has the value 0xcdcdcdcd).

Thanks

##### Share on other sites
Ok, now I'm getting "Unhandled exception at 0x00425cd6 in project0.exe: 0xC0000005: Access violation reading location 0xcdcdcdd9."

Only, its in the vector header file at the second line of this block:

	size_type size() const		{	// return length of sequence		return (_Myfirst == 0 ? 0 : _Mylast - _Myfirst);		}

Basically, there is a class that has a vector of messages waiting to be posted with things like what text to post, what rectangle to post it in, and what font and color it is. Each frame, it uses the specified font (font->DrawTextW( ... )) with the other variables in the structure to draw the text. It gives me the above error. Help?

##### Share on other sites
Quote:
 Original post by bobFritzelpuffOk, now I'm getting "Unhandled exception at 0x00425cd6 in project0.exe: 0xC0000005: Access violation reading location 0xcdcdcdd9."Only, its in the vector header file at the second line of this block: size_type size() const { // return length of sequence return (_Myfirst == 0 ? 0 : _Mylast - _Myfirst); }Basically, there is a class that has a vector of messages waiting to be posted with things like what text to post, what rectangle to post it in, and what font and color it is. Each frame, it uses the specified font (font->DrawTextW( ... )) with the other variables in the structure to draw the text. It gives me the above error. Help?

This is your opportunity to apply what you have learned from your earlier mistake. These errors are similar. Consider what caused your previous problems and how you fixed them. See how far you get on your own.

##### Share on other sites
I've been trying for the past hour or two, with few results. I made sure that the graphics class was declared before the class that holds the messages, and that the class with the messages was declared before the messages were displayed. I even put a default message in the vector that holds messages, just in case. I can't think of what else to try.

Originally, I was having the message holding class make the font itself (it was passed a pointer to the D3DDevice), and I got the unhandled exception error on the line where the D3DDevice was used (even though I was pretty sure that the device was initialized first), so I reworked it so the message class simply tells the graphics class to make a font for it, and reduced the message class to only holding messages. Thats when I got the unhandled exception pointing to the block of code in the vector file, and is where I got lost.

##### Share on other sites
Quote:
 Original post by bobFritzelpuffI've been trying for the past hour or two, with few results. I made sure that the graphics class was declared before the class that holds the messages, and that the class with the messages was declared before the messages were displayed. I even put a default message in the vector that holds messages, just in case. I can't think of what else to try.Originally, I was having the message holding class make the font itself (it was passed a pointer to the D3DDevice), and I got the unhandled exception error on the line where the D3DDevice was used (even though I was pretty sure that the device was initialized first), so I reworked it so the message class simply tells the graphics class to make a font for it, and reduced the message class to only holding messages. Thats when I got the unhandled exception pointing to the block of code in the vector file, and is where I got lost.

Use a debugger to obtain a call stack. You should be able to see where it is failing.

##### Share on other sites
Erm.... no idea how to do that. Sorry, I'm self taught, and the most I can do with debugging is run the basic debugging, setting break points, reading the output, and seeing what line things break on. I haven't been able to find any good debugger documentation, because so many of them are so different.

• 10
• 9
• 48
• 12
• 10
• ### Forum Statistics

• Total Topics
631383
• Total Posts
2999687
×