Okay, so I tested the size of bitmapPtr->infoHeader.biSizeImage and it's 25602 bytes, which is not divisble by 4. It winds up being 6400.5, which I guess makes it 6400 in the allocation line. Then in the read line it reading 6400.5, which I guess is a problem. Would this cause heap corruption?
In this part of the code I'm reading in a 32-bit bitmap's pixels, so I was assuming the size of the image should be divisible by 4, which is not. Should I just treat the tempBuffer as a char* to avoid this problem?
Here's the function code so you can see what's going on
struct Bitmap32{ BITMAPFILEHEADER fileHeader; BITMAPINFOHEADER infoHeader; unsigned int *buffer;};int MyLoadBitmap( char *fileName, Bitmap32 *bitmapPtr ){ // - loads a bitmap with the specified filename and saves the image in a 32-bit buffer // R [1] success // R [0] failure ifstream bitmapFile; bitmapFile.open( fileName, ios::binary | ios::in ); if( bitmapFile.is_open() ) { // read in the file header bitmapFile.read( (char *)&(bitmapPtr->fileHeader), sizeof(BITMAPFILEHEADER) ); // make sure it's a bitmap file if( bitmapPtr->fileHeader.bfType != 0x4D42 ) { bitmapFile.close(); return 0; // file was not a bitmap } // read in the info header bitmapFile.read( (char *)&(bitmapPtr->infoHeader), sizeof(BITMAPINFOHEADER) ); // make sure the bitmap is 32-bit if( bitmapPtr->infoHeader.biBitCount != 32 ) { bitmapFile.close(); return 0; // bitmap was not 32-bit } // allocate a temporary buffer int bufferSize = bitmapPtr->infoHeader.biSizeImage / 4; unsigned int *tempBuffer = new unsigned int[ bufferSize ]; // read in the buffer bitmapFile.read( (char *)tempBuffer, bitmapPtr->infoHeader.biSizeImage ); delete [] tempBuffer; // this is just to test the delete problem // flip the buffer because windows stores the colors are BGRA and opengl wants RGBA unsigned char red = 0; unsigned char green = 0; unsigned char blue = 0; unsigned char alpha = 0; unsigned int *curPos = tempBuffer; for( int i = 0; i < bufferSize; i++ ) { blue = *curPos; green = *curPos >> 8; red = *curPos >> 16; alpha = *curPos >> 24; *curPos = ((alpha << 24) + ((blue) << 16) + ((green) << 8) + (red)); curPos++; } // delete any previous bitmap buffer data if( bitmapPtr->buffer != NULL ) { delete [] bitmapPtr->buffer; bitmapPtr->buffer = NULL; } // assign the buffer to point to the new buffer bitmapPtr->buffer = tempBuffer; return 1; } else return 0; // file could not be opened} // end of MyLoadBitmap