Jump to content

  • Log In with Google      Sign In   
  • Create Account


LoadGLTextures() crash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Neil A Roy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 30 March 2011 - 07:37 PM

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[i]);
  	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[i]->sizeX, TextureImage[i]->sizeY,
               	0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->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[i])	{
  		  	if (TextureImage[i]->data) free(TextureImage[i]->data);
        	free(TextureImage[i]);
  		}
  	}

   return Status;										// Return The Status
}


Sponsor:

#2 karwosts   Members   -  Reputation: 832

Like
0Likes
Like

Posted 30 March 2011 - 08:03 PM

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.
My Projects:
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game

#3 Neil A Roy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 30 March 2011 - 08:32 PM

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.

#4 Neil A Roy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 31 March 2011 - 07:23 PM

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.

#5 karwosts   Members   -  Reputation: 832

Like
0Likes
Like

Posted 31 March 2011 - 07:49 PM

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?)
My Projects:
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS