glubuild2dmipmaps segfaults

Hello, i have been porting a small graphics app which i drew in windows to linux and have come across problems when loading textures, the following code causes a segfault when it gets to the mipmaps call (im using a 4 channel image)

I have used GDB to step through the code but cant see anything wrong with the parameters, what have i done wrong here?

The width and height parameters are correct and the memory is allocated and read correctly.

void CTexData::LoadFile()
{
    
	SDDBData TextureImage;
	// Load The Bitmap
	TextureImage=LoadImage(strFileName.c_str());
	 
	cerr << "Loaded image
";
	//Create Texture
	glGenTextures(1, &uiTexture);

	// Create Nearest mipmapped Texture
	glBindTexture(GL_TEXTURE_2D, uiTexture);
 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    
	glPushAttrib(GL_CURRENT_BIT);
    
	if(!TextureImage.cpData)
	{
		cerr << strFileName.c_str() << "
";
	}
	
	
	
	//These functions are segfaulting!! Pointer is not null!
	if(TextureImage.cChannels ==3) //RGB
	{
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage.uiWidth, 
					TextureImage.uiHeight, GL_RGB, 
					GL_UNSIGNED_BYTE, TextureImage.cpData);
	}
	
	if(TextureImage.cChannels ==4) //RGBA
	{
		gluBuild2DMipmaps(GL_TEXTURE_2D, 4, TextureImage.uiWidth, 
					TextureImage.uiHeight, GL_RGBA, 
					GL_UNSIGNED_BYTE, TextureImage.cpData);
	}
	
	glPopAttrib();
	
	// Free The Texture Image Memory
	delete[] TextureImage.cpData;	
	cerr << "openGL image Funcs called
";

}

the backtrace from GDB is this:

#0  0x40370121 in __strtod_internal () from /lib/tls/libc.so.6
#1  0x402357c6 in __gluTessErrorString ()
   from /usr/X11R6/lib/libGLU.so.1

if it is important i am using the ATI drivers not Mesa or NVidia

Never mind, solved it. For those who may have a similar problem make sure that you have finished intialising your openGL stuff first

i moved my load textures routine from before the following code to the end and that solved the problem

//Activate window
	glXMakeCurrent(dpy, glwin, cx); 
	
	XMapWindow(dpy, glwin); 
	XIfEvent(dpy,  &event,  WaitForMapNotify,  (char *)glwin); 
	
	InitGL(); 
	Resize(WINDOW_WIDTH, WINDOW_HEIGHT); 

You can usually call your texture loading function “after” you make the DC cuurent with the RC…which is aftrer you create your pixelformatdescriptor… Even before your Init function.

But, maybe Lynux a little different.