PDA

View Full Version : glTexImage2D seg fault (Linux)



gib
08-06-2002, 12:23 AM
I have run into a problem using textures. I create several textures, do some drawing, delete the textures, then do it all over again. I am getting a segmentation fault the second time I create the textures, on the first call to glTexImage2D(). I have ascertained that the problem is related to the setting of a parameter.

In the function where I use the textures, after glBindTexture(), I do

glPixelStorei(GL_UNPACK_ROW_LENGTH, width);

where width is the frame width. If width is greater than 521, I get a seg fault later when I try to recreate the textures.
I have a simple code example that manifests this problem, but I don't know how to post it here.

What am I doing wrong?

Gib

Deiussum
08-06-2002, 04:14 AM
What exactly are you trying to do? width in your example should be the width of the image you are giving to glTexImage2d. I have never used this feature, but I am assuming it would be used for a case like this.

Assume you have an image that is 300x300 and the portion of it from 0,0 to 255, 255 is the section you want to use as a texture. You would set the GL_UNPACK_ROW_ALIGNMENT to 300 so that when it would get data for the next row it would skip the data for 256-299.

I'm guessing the reason you are getting a seg fault is because your image data has no such padding, and therefore you are causing glTexImage2D to read past the end of your image array.

gib
08-06-2002, 12:36 PM
The point was that the texture creation works fine the first time, but the second time through the loop causes a seg fault. I have found the solution. It seems that this is one of the situations where it is necessary to save and restore the client attributes.

I have put glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT) before the draw() call, and glPopClientAttrib() after it, and now the test program and my real program both work as intended.

Gib

gib
08-06-2002, 01:09 PM
The point was that the texture creation works fine the first time, but the second time through the loop causes a seg fault. I have found the solution. It seems that this is one of the situations where it is necessary to save and restore the client attributes.

I have put glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT) before the draw() call, and glPopClientAttrib() after it, and now the test program and my real program both work as intended.

Gib