I’m getting some odd, unexplained errors and crashes in my program. I’ve been stepping through debugging and looking around, and I noticed that I’m setting a variable to NULL, but if I set a breakpoint immediately after, the variable is set to 0xcdcdcd00 even though I just set it to NULL.
It looks like there is some sort of memory corruption happening in my program.
What are some good techniques for finding the cause of the memory corruption? I added a large chunk of code before this started happening, so while going through my code, what are something I should be looking for that can cause memory corruption?
I have a class called monster, derived from a class called mob
I execute the following code:
monster* newMon = new monster();
which calls the constructor on monster class:
monster::monster() : mob() {
this->renderer = NULL;
}
when I break at the end of this function, renderer = 0xcdcdcd00 or sometimes 0xcdcdcdcd
This
sets
rendererto NULL. I’d change it tobut that shouldn’t make a difference (other than readability).
The problems is one of two things:
rendereris not NULL, but you shouldn’t trust the debugger in a release build.I’m sure that if you output some debug statements, you’ll see that the value is actually set correctly: