Please view this image of the crash after I choose to debug it in MVS2010:
http://i48.tinypic.com/dr8q9u.jpg
Here’s the Game.h header that shows the Game class structure, and in the picture you will see the offending method that’s causing the access violation (setBot(botInfo * b)).
class botInfo; // Forward declaration
class Game {
int gameState;
int flagDropTime;
botInfo * bot;
public:
Game();
~Game(void);
void startGame();
void gameOver(int victoriousTeam);
void resetBall();
void hideBall();
int getState();
void setBot(botInfo * bot);
botInfo * getBot();
};
From an instance of botInfo (another class) I’m calling a function with this code,
(Game _dsbTrench is a member variable of the botInfo instance).
botInfo * botPointer = this;
_dsbTrench->setBot(botPointer);
Problem is, whenever I call this it causes an exception:
Unhandled exception at 0x72332569 (PubBot.dll) in MERVBot.exe: 0xC0000005: Access violation writing location 0xcdcdcdd5.
So whats the cause of this error? And how can I fix it?
Thanks.
I don’t think there is enough information for me to help. But I will try.
You are writing to memory that is not assigned to your program by the operating system — you need to allocate the memory before you write to it.
— edit —
As mentioned by the other answers”0xCDCDCDCD” is a sentinel variable used for uninitialized words.