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
	cerr << "Loaded image
	//Create Texture
	glGenTextures(1, &uiTexture);

	// Create Nearest mipmapped Texture
	glBindTexture(GL_TEXTURE_2D, uiTexture);
		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);
	// 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/
#1  0x402357c6 in __gluTessErrorString ()
   from /usr/X11R6/lib/

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); 

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.