Hi,
I have simple CTexture class which I use to load bitmaps. Everything works fine untill I want to delete CTexure object.
Then program crash with "DAMAGE: after Normal Block..." message.
The application only crashes in debug mode, in release mode it
works fine. (I use VS 6.0)
I have tried to load two different bitamps:
First bitmap: Resoltution 256x256 the app crashes
Second bitmap: Resolution 562x168 the app works fine
Load bitmap function:
unsigned char* CTexture::LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
unsigned int imageIdx = 0;
unsigned char tempRGB;
unsigned char* imageData;
filePtr = fopen(filename, "rb");
if (filePtr == NULL)
return NULL;
fread(&m_BitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
if (m_BitmapFileHeader.bfType != BITMAP_ID)
{
fclose(filePtr);
return NULL;
}
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
fseek(filePtr, m_BitmapFileHeader.bfOffBits, SEEK_SET);
imageData = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
if (!imageData)
{
free(imageData);
fclose(filePtr);
return NULL;
}
fread(imageData, 1, bitmapInfoHeader->biSizeImage, filePtr);
if (imageData == NULL)
{
fclose(filePtr);
return NULL;
}
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = imageData[imageIdx];
imageData[imageIdx] = imageData[imageIdx + 2];
imageData[imageIdx + 2] = tempRGB;
}
fclose(filePtr);
return imageData;
}
//Setup method
bool CTexture::SetupTexture(char* filename)
{
m_pBitmapData = LoadBitmapFile(filename, &m_BitmapInfoHeader);
//I deleted whole opengl code but it still dosen't work
}
Destructor:
CTexture::~CTexture()
{
if(m_pBitmapData != NULL)
free(m_pBitmapData);
m_pBitmapData = NULL;
}
Thanks in advance for help.
[edited by - BigMac on May 21, 2004 6:56:45 PM]