I'm using GL_SELECT to select objects in my application, and I'm getting some strange behavior. It seems that the selection buffer is never reset, even though I am calling glRenderMode (GL_RENDER) after selection, and am calling glSelectBuffer () before each selection. Here's my code:

buffer = self.view.paintGL (GL.GL_SELECT, x, y)
print "Selection returned %d hits:" % (len (buffer), )

where self.view.paintGL is defined as:

def paintGL (self, mode = GL.GL_RENDER , pickX = 0, pickY = 0):
    # Initialize the rendering deleages.
    self.getGeometry ()

    if mode == GL.GL_SELECT:
        # Set up the selection buffer.
        GL.glSelectBuffer (512)

    GL.glRenderMode (mode)

    # Initialize the name stack.
    GL.glInitNames ()
    GL.glPushName (0)

    if self.useDisplayLists:
        # Call the display lists to set up drawing options and
        # transformation matrices.
        GL.glCallList (self.drawOptionsListId)
        GL.glCallList (self.windowTransformListId)
        GL.glCallList (self.userTransformListId)

    if mode == GL.GL_SELECT:
        # Save the current projection matrix.
        GL.glMatrixMode (GL.GL_PROJECTION)
        prevMatrix = GL.glGetDoublev (GL.GL_PROJECTION_MATRIX)

        # Set up the picking matrix.
        viewport = GL.glGetIntegerv (GL.GL_VIEWPORT)
        GL.glLoadIdentity ()
        GLU.gluPickMatrix (pickX, pickY, 3, 3, viewport)
        GL.glMultMatrixd (prevMatrix)

        # Return to MODELVIEW matrix mode.
        GL.glMatrixMode (GL.GL_MODELVIEW)

    # Clear the view to the background color.
    self.qglClearColor (self.colorScheme.background)

        # Render the scene.
        for delegate in self.delegates :
            delegate.render ()
    except GL.GLerror, inst:
        self.log ("ERROR", str (inst))

    GL.glFlush ()

    if mode == GL.GL_SELECT:
        # Restore the original projection matrix.
        GL.glMatrixMode (GL.GL_PROJECTION)
        GL.glLoadMatrix (prevMatrix)

    if mode != GL.GL_RENDER:
        # Exit selection or feedback mode, and return the
        # selection buffer or the feedback array.
        return GL.glRenderMode (GL.GL_RENDER)

In the above code, self.useDisplayLists is True.
And here's the output from clicking on the same object repeatedly:

Selection returned 32 hits:
Selection returned 34 hits:
Selection returned 36 hits:
Selection returned 38 hits:
Selection returned 40 hits:
Selection returned 122 hits:
Selection returned 124 hits:
Selection returned 126 hits:
Selection returned 128 hits:
Traceback (most recent call last):
  File "/home/whitelynx/gne/dbz/widgets/GL3DView.py", line 525, in mouseReleaseEvent
    handler.click (event.x (), event.y ())
  File "/home/whitelynx/gne/dbz/widgets/ButtonHandlers.py", line 9, in click
    buffer = self.view.paintGL (GL.GL_SELECT, x, y)
  File "/home/whitelynx/gne/dbz/widgets/GL3DView.py", line 213, in paintGL
    return GL.glRenderMode (GL.GL_RENDER)
OpenGL.GL.GLerror: [Errno (1283,)] glSelectBuffer too small to hold selection results

Any ideas what I'm doing wrong?

David H. Bronke
Vice President of Project Development
G33X Nexus Entertainment

v3sw5/7Hhw5/6ln4pr6Ock3ma7u7+8Lw3/7Tm3l6+7Gi2e4t4Mb7Hen5g8+9ORPa22s6MSr7p6 hackerkey.com
Support Web Standards! http://www.webstandards.org/