Texture Deletion Oddity

I’m wrote a Texture manager class. It contains texture id’s as issued by OpenGL, with key’s to these Id’s set to the filename of the texture itself.

There is a method called deleteAll that deletes all textures being managed.


public void deleteAll() {
        LoggingSystem.getLoggingSystem().getLogger().log(Level.INFO,
            "Deleting All Textures");
        int id;
        String key;
        for(int i = 0; i < keyList.size(); i++) {
            key = ((TextureData)keyList.get(i)).file;
            id = ((Integer)textureList.get(key)).intValue();
            if(gl.isTexture(id)) {
                gl.deleteTextures(1, id);
            }
        }
        
        textureList.clear();
        keyList.clear();
    }

I’m having trouble with this call, specifically gl.deleteTextures(1, id).

I’m getting the following error:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0xEF8CD90
Function=[Unknown.]
Library=C:\WINNT\System32\nvoglnt.dll

NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.

Current Java thread:
at org.lwjgl.opengl.CoreGL.deleteTextures(Native Method)
at monkey.texture.TextureManager.deleteAll(TextureManager.java:367)
at monkey.texture.TextureManager.reload(TextureManager.java:104)
at monkey.Game.mainLoop(Game.java:92)
at monkey.Game.start(Game.java:59)
at monkey.Game.main(Game.java:74)

with a long list of dynamic libraries.

This only seems to happen after I have changed the screen resolution and thus gl.destroy and gl.create have been called. I thought it may be due to me trying to delete a texture that doesn’t exist, but I added the

if(gl.isTextured(id))

statement to take care of this. Any ideas?

Thanks,
Mark

By the 1.4 spec, the call in question is:

void DeleteTextures( sizei n, uint *textures );

As this is a pointer to an array of unsigned integers, LWJGL will require you to pass it the address of an IntBuffer containing the id, even if there’s only one id.

Also, it’s possible that after deleting the GL context, all loaded textures will have been destroyed. I have no idea whether this is true though.

The “if(gl.isTexture(id))” check works because that takes the id directly, rather than a pointer to it.

Ah thank you! I’ve been staring at the reference for glDeleteTextures in the blue book forever, and kept glazing right over the pointer. It’s amazing how switching API and languages can really humble you when it comes to something you “thought” you knew how to do. :slight_smile:

Thanks again.