glGenTextures starts repeating results


I’m doing a little app that displays some images. Basically I’m loading a few hundred photos from disk and display them. I’m trying to write a simple texture manager to handle mipmapping and streaming of the textures from the disk, since some of the photos can be quite large (4000x4000+).

When my app starts, it tries to load scaled down version (like ~100x100) of every image, so that I always have something to show. I stream larger versions of the images when needed.

My problem is that during this initial loading of the small textures, glGenTextures starts returning the same texture IDs.

Here’s a log of texture IDs created:

created id 2, error GL_NO_ERROR
created id 6, error GL_NO_ERROR
created id 7, error GL_NO_ERROR
created id 8, error GL_NO_ERROR


created id 277, error GL_NO_ERROR
created id 278, error GL_NO_ERROR
created id 279, error GL_NO_ERROR
created id 7, error GL_NO_ERROR


I’m at loss why this is happening. I don’t release any textures while loading. If I let my app run, I get weird results like some images not appearing and others show multiple times. Any ideas what might be wrong? The texture IDs I generate one at a time using glGenTextures(1, &id).

My app runs on Linux and here’s some driver info:

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 7950 GT/PCI/SSE2
OpenGL version string: 2.1.0 NVIDIA 97.46

That sounds weird as glGenTextures is guaranteed to always return different ids unless you glDeleteTextures one of them.
Do you maybe get a GL_ERROR somewhere else?

1 Like

Find every place in your code where you delete texture and put breakpoint there. Make sure you don’t call glDeleteTextures somewhere.
If you do - see what id you pass - perhaps your code has a bug and you delete wrong textures.

Thanks your comment save me from my headache bug!