I always encapsulate memory allocations inside shared_ptr's, like this:
boost::shared_ptr<Sprite> sprite = boost::shared_ptr<Sprite>( new Sprite(32, 32) );
This is where one of the errors occurs. The Sprite constructor finishes, but the shared_ptr constructor gives an error: "0xC0000005: Access violation writing location 0xcdcdcdd1." Before now, everything worked perfectly, and I did not change any line which is executed before this one.
The other errors I'm getting are weirder. For example (the following code also worked perfectly before I started getting the memory errors):
bool Spell::isOnTarget(){ // targetCharacter is of type boost::shared_ptr<Character> // x, y and targetCharacter are member variables of Spell if(( x == targetCharacter->x ) && (y == targetCharacter->y )) return true; else return false;}
This never returns true, even when the coordinates are equal; I've tested situations when the spell should definitely be on target. When debugging with VC++, I can even check from the local variables window that x and targetCharacter->x, etc. are equal, yet, the condition still evaluates to true. If I change the code to this:
bool Spell::isOnTarget(){ int tempX = targetCharacter->x; int tempY = targetCharacter->y; if(( x == tempX ) && (y == tempY )) return true; else return false;}
then it works.
All this doesn't seem to make any sense. Probably the heap gets corrupted somehow, but I don't have any experience debugging memory corruptions, so I don't know what to do. All calls to the new operator are encapsulated in boost::shared_ptr constructors, so they shouldn't be any memory leaks. I've tried rebooting Windows XP, but it didn't help either.
My game runs in a single thread, although I think some Allegro timer routines run in a separate thread.
Which steps should I take to debug this?
[Edited by - formalproof on July 7, 2010 4:17:46 PM]