LoadGLTextures() crash

Started by
3 comments, last by karwosts 13 years ago
I just got into programming again after a bit of a break from it. My operating system has changed and I moved from using WindowsXP to Windows 7 64bit.

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
}
Advertisement
Have you inspected the values that you're freeing during debugging and made sure they are pointing to what you expect?

Is LoadBMP actually malloc'ing your textures? You make a claim here:


AUX_RGBImageRec *TextureImage[7]; // Create Storage Space For The Texture


that you're "creating storage space", but really all you're doing is creating some pointers, not actually creating any storage.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Than you better talk to NeHe because that is straight out of his code, not mine. :) That is his comments, and this code compiled up fine on Windows XP. It still does if I don't try freeing memory all the textures show up just fine proving something IS being loaded (or I wouldn't see the textures, now would I?).

Like i said, I didn't write that code or comment, that was from NeHe's code.
Just to update, I compiled my program and this crash ONLY happens under Windows 7 64bit. When I run the same program under Windows XP 32bit it runs fine.
You'll probably have to do some more digging in the debugger, maybe the code wasn't written as safe to be on 64 bit (assumed int = 4 bytes or something like that, I don't know). I'd start digging into the loadBMP function to see what's going on, also find out which call exactly is causing the crash (does it crash on free when i is 0, or some other number?)
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement