This discussion is archived
0 Replies Latest reply: Dec 22, 2010 11:49 AM by 826077 RSS

Retrieving PickResults results in a java.lang.IllegalStateException error

826077 Newbie
Currently Being Moderated
I'm attempting to manipulate a scene based on where the user clicks on the canvas. I use a wrapper class that contains a PickCanvas object to return the pick result. I also extend MouseAdapter class so I can catch the mouse click event on the canvas.

The PickCanvas object returns the first pick Shape3D object fine. However, whenever the user picks the second Shape3D object, I get the following error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Picking can only work if BranchGroup is alive
at javax.media.j3d.BranchGroup.pickAll(BranchGroup.java:162)
at com.sun.j3d.utils.picking.PickTool.pickGeomAllSorted(PickTool.java:712)
at com.sun.j3d.utils.picking.PickTool.pickGeomClosest(PickTool.java:792)
at com.sun.j3d.utils.picking.PickTool.pickClosest(PickTool.java:574)
at org.osskbe.experimental.genesis.graphics.pick.GraphicsPick.mouseClicked(GraphicsPick.java:32)

GraphicsPick is my wrapper class. The following is an example of how I implemented GraphicsPick:
public class GraphicsPick extends MouseAdapter {
     private final PickCanvas pickCanvas;

     public GraphicsPick(Canvas3D canvas, BranchGroup root) {
          pickCanvas = new PickCanvas(canvas, root);
          pickCanvas.setMode(PickCanvas.GEOMETRY);
          canvas.addMouseListener(this);
     }

     @Override
     public void mouseClicked(MouseEvent mouseEvent) {
          pickCanvas.setShapeLocation(mouseEvent);
          PickResult result = pickCanvas.pickClosest();
          if (result == null) {
               System.out.println("Nothing picked");
          } else {
               System.out.println("x = " + mouseEvent.getX() + " y = " + mouseEvent.getY());
               Primitive prim = (Primitive) result.getNode(PickResult.PRIMITIVE);
               Shape3D shape = (Shape3D) result.getNode(PickResult.SHAPE3D);
               // manipulate shape3D object
          }

     }
}
The exception occurs the following line of code from above is executed:
          PickResult result = pickCanvas.pickClosest();
Note: For each Shape3D object, I've enabled the following capabilities:
// Enable picking
shape.setPickable(isPickable);
shape.setCapability(Node.ENABLE_PICK_REPORTING);
PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);
The scene is updated each time the user clicks on the scene on a allowable Shape3D object. I was thinking that maybe the problem lies in associating the Canvas3D object with multiple PickCanvas's since I'm working on different scenes throughout the user interaction. I'm unsure what the problem is. Any help will be greatly appreciated.

Edited by: user13531972 on Dec 22, 2010 11:48 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points