Foreground node + picking = exception

Trying to use view.pick() to pick a quad drawn on a Foreground node. When I do, I get the following exception only when the coordinates are within the quad (ie, successful pick):

java.lang.NegativeArraySizeException
at com.xith3d.render.jogl.CanvasPeerImpl.convertSelectBuffer(CanvasPeerImpl.java:841)
at com.xith3d.render.jogl.CanvasPeerImpl.renderDone(CanvasPeerImpl.java:877)
at com.xith3d.render.jogl.CanvasPeerImpl.display(CanvasPeerImpl.java:1076)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:198)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:239)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:186)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:74)
at com.xith3d.render.jogl.CanvasPeerImpl.render(CanvasPeerImpl.java:1156)
at com.xith3d.scenegraph.View.pick(View.java:619)
at CRG_World3D.getPickRenderResult(CRG_World3D.java:51)
at CRG_GUI.Message(CRG_GUI.java:73)
at CRG_Manager.Broadcast(CRG_Manager.java:123)
at CRG_Keyboard.update(CRG_Keyboard.java:80)
at CRG_Manager.runCycle(CRG_Manager.java:97)
at CRG_VXI.go(CRG_VXI.java:17)
at CRG_VXI.main(CRG_VXI.java:36)

Any thoughts? It only seems to happen on what would have been a successful pick otherwise.

Here’s the relevant code from jogl/CanvasPeerImpl.java:


public void renderDone()
    {
      super.renderDone();
      if (pickMode)
      {
        gl.glFlush();
        pickRenderResults = convertSelectBuffer(gl.glRenderMode(GL.GL_RENDER));
      }
    }


private PickRenderResult[] convertSelectBuffer(int count)
    {
      PickRenderResult[] results = new PickRenderResult[count];
   ...

It appears the gl.glRenderMode(GL.GL_RENDER) call is returning a negative value. It’s that value being passed to convertSelectBuffer() as the size of the array to be created.

Picking of Foreground nodes hasn’t been tested until now so I am not surprised you are having problems. Have you tried picking the object when it isn’t attached to a Foreground? You can move the View to (0,0,0) to get the same affect as the Foreground node.

I’ve never used picking in Xith3D, hopefully someone more experianced in this area can help you.

Will.

I wouldn’t even need to use the official Xith picking if I could just figure out a screen coords -> Foreground coords equation, for a given depth from the camera. But my numbers just aren’t coming out right yet, and I’ve been working 4 days on it.

Figured it out…

Where canvasTanFOV is equal to Math.tan(canvas.getFOV()), but I only calculate that once :slight_smile:

tan(f)=opp / adj, where we know the f=FOV, adj = depth, and calculate O. Then it’s scaled by the screen coords.

nice one.

should we add that method to Canvas?

I assume your code still works even when the canvas is an unusual apect ration (e.g. widescreen)? I looks like it would, I’m just woundering if you have tryed it.

Will.

I dunno, it works for me at 800 x 600 at least :slight_smile:

can you try resizing the window?

I remember this was a limitation of the old UI system.

Will.