Object Selection problems

Hi,

does anyone have an idea why my program crashes when I try to make glSelectBuffer - call. I’m trying to find out what object user has clicked on and the code uses glSelectBuffer to achieve this.


/* (non-Javadoc)
       * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
       */
      public void mousePressed(MouseEvent e) {
            System.out.println("MousePressed");
            int x = e.getX();
            int y = e.getY();
            
            int objectsFound = 0;                              // This will hold the amount of objects clicked
            int viewportCoords[] = new int [4];            // We need an array to hold view port coordinates
            int selectBuffer[] = new int [32];
            
            gl.glSelectBuffer(32, selectBuffer);      // Setup selection buffer to accept object ID's. PROGRAM CRASHES IN HERE!
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewportCoords); // Get the current view port coordinates
            gl.glMatrixMode(GL.GL_PROJECTION);            // We want to now effect projection matrix

...

I had asked the same question earlier as got -

Yes, there are restrictions on when OpenGL calls can be made in JOGL. It is only valid to use the GLDrawable’s GL object from within one of the GLEventListener’s methods (init(), reshape(), display(), and displayChanged()).