I can't for the life of me figure this error out and it's driving me crazy, so hopefully someone on here can help me out.
// allocate a temporary buffer
int bufferSize = bitmapPtr->infoHeader.biSizeImage / 4;
unsigned int *tempBuffer = new unsigned int[ bufferSize ];
// read in the buffer, bitmapFile is an ifstream
bitmapFile.read( (char *)tempBuffer, bitmapPtr->infoHeader.biSizeImage );
// this doesn't work
delete [] tempBuffer;
When that code runs, I get this error:
HEAP CORRUPTION DETECTED: after Normal block(#134) at 0x00386CA0.
CRT detected that the application wrote to memory after end of heap buffer.
But I don't get the error with this code...
// allocate a temporary buffer
int bufferSize = bitmapPtr->infoHeader.biSizeImage / 4;
unsigned int *tempBuffer = new unsigned int[ bufferSize ];
// this does work, why!?
delete [] tempBuffer;
// read in the buffer, bitmapFile is an ifstream
bitmapFile.read( (char *)tempBuffer, bitmapPtr->infoHeader.biSizeImage );
What is happening to tempBuffer during the bitmapFile.read to cause it have heap curruption if I try to delete it after that line? Am I'm using the pointer wrong by casting it to a char pointer?
The problem isn't directy in this part of the code, but I added the delete there to figure out where my program was messing up. The real problem happens later when I try to delete the memory that I allocated here and I get the crazy heap corruption business :( I figure this little snippet of code is basically the problem.
I'm using VS2005, not sure if that helps or not or if I'm missing some other information, but if I forgot something important, tell me and I'll let you know.