I loaded up some old code I had worked on and it now crashes in the following code:
If I comment out the code that attempts to free TextureImage it crashes, but runs fine if I comment that out (but obviously that then creates a leak). The textures load and display just fine, no problems so long as I comment that out. It never used to crash before.
OS: Windows 7 64bit
Compiler: Code::Blocks with MinGW 4.5.2
It used to work when I used Windows XP and compiled this with Dev-C++ (MinGW 3.4.2 I think it was). The code itself was never changed by me between then and now.
Any ideas?
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
int i;
AUX_RGBImageRec *TextureImage[7]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*7); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
TextureImage[0]=LoadBMP("Data/grass.bmp");
TextureImage[1]=LoadBMP("Data/FlatRoadNS.bmp");
TextureImage[2]=LoadBMP("Data/FlatRoadEW.bmp");
TextureImage[3]=LoadBMP("Data/FlatRoadSE.bmp");
TextureImage[4]=LoadBMP("Data/FlatRoadSW.bmp");
TextureImage[5]=LoadBMP("Data/FlatRoadNW.bmp");
TextureImage[6]=LoadBMP("Data/FlatRoadNE.bmp");
Status=TRUE;
glGenTextures(7, &texture[0]); // Create The Texture
for(i=0; i<7; i++) {
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->sizeX, TextureImage->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);
}
// It crashes when it tries to free memory here, if I comment this out, it runs just fine.
for (i=0; i<7; i++) {
if (TextureImage) {
if (TextureImage->data) free(TextureImage->data);
free(TextureImage);
}
}
return Status; // Return The Status
}