glTexImage2D segmentation fault

I have been working on code developed from glmovie.c, and I’ve run into
a problem. I can play an mpeg that gets handled as 16 256x256 texture
tiles, everything OK at this stage. But if I terminate the mpeg then
reopen it (in the same program) I get a seg fault. The error occurs in
the initialization stage, (glmovie_init()). For each of the 16 tiles, a
texture is created. The seg fault occurs when glTexImage2D() is first
called the second time the mpeg is started.

It is hard to see what could be wrong with the call, which is:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGBA,
GL_UNSIGNED_BYTE, pixels);

where pixels is a pointer to 2562564 bytes which has just been
allocated.

I’m wondering if something more needs to be done to free memory used the
first time the mpeg is played. I do this:

if (mpeg) {
SMPEG_stop(mpeg);
SMPEG_delete(mpeg);
}
if (texture_ids) {
glDeleteTextures(num_texture_rows*num_texture_cols, texture_ids);
free(texture_ids);
free(textures);
}

Obviously the problem is somehow related to the first playing of the
mpeg.

Maybe some else has seen a similar thing happen.

Gib

I have been working on code developed from glmovie.c, and I’ve run into
a problem. I can play an mpeg that gets handled as 16 256x256 texture
tiles, everything OK at this stage. But if I terminate the mpeg then
reopen it (in the same program) I get a seg fault. The error occurs in
the initialization stage, (glmovie_init()). For each of the 16 tiles, a
texture is created. The seg fault occurs when glTexImage2D() is first
called the second time the mpeg is started.

It is hard to see what could be wrong with the call, which is:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGBA,
GL_UNSIGNED_BYTE, pixels);

where pixels is a pointer to 2562564 bytes which has just been
allocated.

I’m wondering if something more needs to be done to free memory used the
first time the mpeg is played. I do this:

if (mpeg) {
SMPEG_stop(mpeg);
SMPEG_delete(mpeg);
}
if (texture_ids) {
glDeleteTextures(num_texture_rows*num_texture_cols, texture_ids);
free(texture_ids);
free(textures);
}

from your sniffed code i can’t see the problem but do you really
reallocate texture_ids and textures? (what is textures?)On Sat, 3 Aug 2002, Gib Bogle wrote:

Obviously the problem is somehow related to the first playing of the
mpeg.

Maybe some else has seen a similar thing happen.

Gib


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Message: 14

I have been working on code developed from glmovie.c, and I’ve run into
a problem. I can play an mpeg that gets handled as 16 256x256 texture
tiles, everything OK at this stage. But if I terminate the mpeg then
reopen it (in the same program) I get a seg fault. The error occurs in
the initialization stage, (glmovie_init()). For each of the 16 tiles, a
texture is created. The seg fault occurs when glTexImage2D() is first
called the second time the mpeg is started.

It is hard to see what could be wrong with the call, which is:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGBA,
GL_UNSIGNED_BYTE, pixels);

where pixels is a pointer to 2562564 bytes which has just been
allocated.

I’m wondering if something more needs to be done to free memory used the
first time the mpeg is played. I do this:

if (mpeg) {
SMPEG_stop(mpeg);
SMPEG_delete(mpeg);
}
if (texture_ids) {
glDeleteTextures(num_texture_rows*num_texture_cols, texture_ids);
free(texture_ids);
free(textures);
}

from your sniffed code i can’t see the problem but do you really
reallocate texture_ids and textures? (what is textures?)

Are you saying my code stinks, Krata ;)?
Sorry, textures is a red herring (as you sniffed). It holds information
about how the textures are used with the tiles, and is irrelevant to
OpenGL. Yes, I do reallocate texture_ids, with

glGenTextures(num_texture_rows*num_texture_cols, texture_ids);

I have written a little test program that does nothing more than create
the 16 textures then delete them, many times, using the same code that
is in my real program (and glmovie.c). This works fine, which seems to
show that there is not an issue with the way textures are being stored.
Since textures are so fundamental I really don’t expect this problem to
be caused by the nVidia driver.

(later)

I have done some more explorations, and I now have another couple of
bits of useful information. One thing is that I can run a different
mpeg, one that uses only 2 tiles, and it runs happily for ever
restarting the same mpeg.

I then found that if I comment out the code that does the actual
displaying of the frames using the textures the problem goes away.
Looking more closely into that subroutine, I find that just doing
glBindTexture() for each of the textures is OK, but simply adding one
glPixelStorei() command (e.g. to set GL_UNPACK_ROW_LENGTH) causes the
seg fault to occur the next time I initialize and do glTexImage2D().

To summarise:

  1. When I repeatedly open and play an mpeg, recreating the textures it
    uses each time, the program runs successfully with an mpeg that needs 2
    tiles (and textures), but gives a seg fault with an mpeg that needs 16
    tiles. The seg fault occurs while executing glTexImage2D().

  2. If the textures are created but not used, i.e. if no drawing is
    performed, the seg fault does not occur.

  3. If in the drawing function the textures are just bound but not
    actually used, no seg fault occurs.

  4. If in the drawing function the textures are bound and also I invoke
    glPixelStorei(), the seg fault occurs.

Input from anyone who is familiar with how textures work would be very
much appreciated. I have only a very hazy idea of how these are handled
by OpenGL and the graphics card.

Just in case it is a Linux driver issue, can someone tell me how to send
nVidia a problem report?

thanks
Gib> Date: Sun, 4 Aug 2002 12:07:45 +0200 (CEST)

From: Krata
To: sdl at libsdl.org
Subject: Re: [SDL] glTexImage2D segmentation fault
Reply-To: sdl at libsdl.org
On Sat, 3 Aug 2002, Gib Bogle wrote: