GLEventListener init is called more than once?

Ahoy!

In this small program there is a JDesktopPane with 3 JInternalFrame-s. In two of the JInternalFrames-s are GLJPanel-s. If I resize these iframes fast a lot of times, init is called randomly /at least randomly for me/. I taught init is called only once per instance. Is this normal behavior or a bug?

package jogl01;

public class Main
{
 public static class MyDesktopPane extends javax.swing.JDesktopPane
 {
  protected MyGLInternalFrame _glFrame;
  protected MyGLInternalFrame _glFrame2;

  public MyDesktopPane ()
  {
   super ();
   this._glFrame = new MyGLInternalFrame ();
   this._glFrame.setBounds (50, 20, 200, 300);
   this._glFrame.setVisible (true);
   this.add (this._glFrame);
   ((javax.swing.plaf.basic.BasicInternalFrameUI) this._glFrame.getUI ())
    .setNorthPane (null);
   this._glFrame2 = new MyGLInternalFrame ();
   this._glFrame2.setBounds (300, 10, 200, 300);
   this._glFrame2.setVisible (true);
   this.add (this._glFrame2);
   javax.swing.JInternalFrame other = new javax.swing.JInternalFrame ("", true);
   other.setBackground (new java.awt.Color (1.0f, 1.0f, 0.0f, 0.3f));
   other.setOpaque (false);
   other.setBounds (200, 200, 200, 200);
   other.setVisible (true);
   this.add (other);
   this.moveToFront (other);
  }
 }

 public static class MyGLInternalFrame extends javax.swing.JInternalFrame
 {
  protected net.java.games.jogl.GLJPanel _glPanel;

  public MyGLInternalFrame ()
  {
   super ("Place of the Title", true);
   net.java.games.jogl.GLCapabilities cap =
    new net.java.games.jogl.GLCapabilities ();
   cap.setHardwareAccelerated (true);
   cap.setDoubleBuffered (true);
   this._glPanel = net.java.games.jogl.GLDrawableFactory.getFactory ()
    .createGLJPanel (cap);
   this._glPanel.addGLEventListener (new net.java.games.jogl.GLEventListener ()
   {
    public void display (net.java.games.jogl.GLDrawable aD)
    {
     net.java.games.jogl.GL gl = aD.getGL ();
     net.java.games.jogl.GLU glu = aD.getGLU ();

     gl.glClear (net.java.games.jogl.GL.GL_COLOR_BUFFER_BIT);

     gl.glBegin (net.java.games.jogl.GL.GL_TRIANGLES);
      gl.glColor4d (1.0, 0.0, 0.0, 0.0);
      gl.glVertex3f ( 0.0f, 0.0f, 0.0f);
      gl.glColor4d (0.0, 1.0, 0.0, 0.5);
      gl.glVertex3f (300.0f, 100.0f, 0.0f);
      gl.glColor4d (0.0, 0.0, 1.0, 1.0);
      gl.glVertex3f ( 100.0f, 300.0f, 0.0f);
     gl.glEnd ();
    }

    public void displayChanged (net.java.games.jogl.GLDrawable aD,
     boolean aModeChanged, boolean aDeviceChanged) {}

    public void      init (net.java.games.jogl.GLDrawable aD)
    {
     net.java.games.jogl.GL gl = aD.getGL ();
     net.java.games.jogl.GLU glu = aD.getGLU ();
     java.util.Random rnd = new java.util.Random ();

     gl.glBlendFunc (net.java.games.jogl.GL.GL_SRC_ALPHA,
      net.java.games.jogl.GL.GL_ONE_MINUS_SRC_ALPHA);
     gl.glClearColor
      (rnd.nextFloat (), rnd.nextFloat (), rnd.nextFloat (), rnd.nextFloat ());
     gl.glDisable (net.java.games.jogl.GL.GL_DEPTH_TEST);
     gl.glEnable (net.java.games.jogl.GL.GL_BLEND);
     gl.glMatrixMode (net.java.games.jogl.GL.GL_PROJECTION);
     gl.glLoadIdentity ();
     glu.gluOrtho2D (0.0f, 800.0f, 600.0f, 0.0f);
     gl.glMatrixMode (net.java.games.jogl.GL.GL_MODELVIEW);
     gl.glLoadIdentity ();
     System.out.println ("Howdie! Init speaking.");
    }

    public void reshape (net.java.games.jogl.GLDrawable aD,
     int x, int y, int width, int height)
    {
     aD.getGL ().glViewport (0, 0, width, height);
    }
   });
   this.add (this._glPanel);
  }
 }

 public static void main (String [] aArgs)
 {
  javax.swing.JFrame f = new javax.swing.JFrame ("Jogl01");
  f.add (new MyDesktopPane ());
  f.setSize (800, 600);
  f.setDefaultCloseOperation (javax.swing.JFrame.EXIT_ON_CLOSE);
  f.setVisible (true);
 }
}

Tested with:
jogl 11b10
Sun Java 1.5.0_01
Windows XP SP2
Gef4 TI4200

This is correct behavior. Your GLEventListener.init() method is called each time an OpenGL context is created for your widget (either a GLCanvas or GLJPanel). Under the hood. a pbuffer is used for hardware acceleration of the GLJPanel. When the GLJPanel is resized to be larger than the pbuffer, the pbuffer is destroyed and a new one is created, so your application might need to set up new state for it.

It’s currently an issue that the new pbuffer happens to share textures and display lists with the old one, so if your init() method reloads textures then there will be a memory leak. To work around this, you could add a flag in your GLJPanel’s GLEventListener to only load the textures the first time through your init() method. In the future this will probably be fixed by not having the underlying pbuffer share display lists with any GLDrawable except those specified by the user, and not by squelching calls to init() (which are still necessary in case other OpenGL state is set up there).

Thank you for your answer.