glDeleteLists causes OutOfMemoryError


      public void glDeleteDisplayList( GL gl ) {
            if (displayList != 0) {
                  gl.glDeleteLists( displayList, 1 );
                  displayList = 0;
            }
      }

This code will cause an OutOfMemoryError for a valid display list number.

The only hit as to what is going on, is that I call canvas.getGL() outside of the display method of GLEventListener.

If I call the above method from inside display then it works.

Why is this?

When a user wants to load a new 3D scene I need to clear all the display lists being used, and I don’t want to do this inside the GLEventListener class, since that doesn’t make sense.

Because your glContext is not valid…

But you must do that! (Or go on the thread stuff if you prefer…)

Any idea on how to make this work?

I mean, when you load in a new 3D scene you delete the old one. Now when you display the next frame, the old scene is gone and you can’t destroy the old display lists.

When an object is first displayed that’s when I compile the display list. So that part’s easy.

Also, users may select and delete objects at runtime. These also need to be removed from the display lists.

Any ideas?

Can’t you simply add a flag and do your loading / unloading from the display method in the GLEventListener.

Or you can remove your old scene, load your new one and still delete the old display lists in the display method and recreate the new ones…

I created a class which contains a queue, and as objects are deleted they are placed into the queue.

When the scene is next rendered the queue is emptyed. Allowing each object to destroy any resources its using on the graphics card. (i.e. display lists, textures, etc… etc…)

Thanks for you advise, this appears to be working.