Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4910683
Votes 12
Synopsis IndexOutOfBoundsException thrown when BranchGroup containing Collision detach
Category java3d:other
Reported Against 1.3
Release Fixed
State 11-Closed, duplicate of 5098683, bug
Priority: 4-Low
Related Bugs
Submit Date 21-AUG-2003
Description


FULL PRODUCT VERSION :
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
RUNNING:
java3d-1_3_1-beta-windows-i586-opengl-sdk

FULL OS VERSION :
Windows 98 [Version 4.10.2222]
Linux 2.4.17 SMP i686 debian 3.0


EXTRA RELEVANT SYSTEM CONFIGURATION :
Laptop, HP Omnibook 6000 running windows and linux.

A DESCRIPTION OF THE PROBLEM :
When I have a BranchGroup node containing a Behaviour Node (like a collision detection), when trying to detach it from the Locale I get an error like:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:507)
        at java.util.ArrayList.get(ArrayList.java:324)
        at javax.media.j3d.Shape3DRetained.getMirrorShape(Shape3DRetained.java:1931)
        at javax.media.j3d.Shape3DRetained.searchGeometryAtoms(Shape3DRetained.java:2767)
        at javax.media.j3d.GroupRetained.searchGeometryAtoms(GroupRetained.java:3105)
        at javax.media.j3d.WakeupOnCollisionEntry.updateCollisionBounds(WakeupOnCollisionEntry.java:419)
        at javax.media.j3d.GeometryStructure.processCollisionDetection(GeometryStructure.java:866)
        at javax.media.j3d.GeometryStructure.processMessages(GeometryStructure.java:214)
        at javax.media.j3d.StructureUpdateThread.doWork(StructureUpdateThread.java:83)
        at javax.media.j3d.J3dThread.run(J3dThread.java:250)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Press R in the example to remove the live box that has also the CollisionHandler class atached. It will throw the exception.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should just remove the box witout problem.
ACTUAL -
It throws the exception that is not cathable in the detach call but somewhere else.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:507)
        at java.util.ArrayList.get(ArrayList.java:324)
        at javax.media.j3d.Shape3DRetained.getMirrorShape(Shape3DRetained.java:1931)
        at javax.media.j3d.Shape3DRetained.searchGeometryAtoms(Shape3DRetained.java:2767)
        at javax.media.j3d.GroupRetained.searchGeometryAtoms(GroupRetained.java:3105)
        at javax.media.j3d.WakeupOnCollisionEntry.updateCollisionBounds(WakeupOnCollisionEntry.java:419)
        at javax.media.j3d.GeometryStructure.processCollisionDetection(GeometryStructure.java:866)
        at javax.media.j3d.GeometryStructure.processMessages(GeometryStructure.java:214)
        at javax.media.j3d.StructureUpdateThread.doWork(StructureUpdateThread.java:83)
        at javax.media.j3d.J3dThread.run(J3dThread.java:250)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
 * testCollision.java
 *
 * Created on October 17, 2002, 11:39 PM
 */
import javax.media.j3d.*;
import java .awt.*;
import javax.vecmath.*;

/**
 *
 * @author  Peter Antoniac
 */
public class testCollision extends javax.swing.JFrame {
  public testCollision() {
    super("Testing Collision removal");
    setSize(300,400);
    getContentPane().setLayout(new java.awt.BorderLayout());
    setBackground(new java.awt.Color(255, 255, 255));
    setName("Testing Window");
    // Create the 3D Objects
    pGTmpl3D = new GraphicsConfigTemplate3D();
    pGConf = getGraphicsConfiguration();
    pGDev = pGConf.getDevice();
    pCanvas3D = new Canvas3D(pGTmpl3D.getBestConfiguration(pGDev.getConfigurations()));
    getContentPane().add(pCanvas3D);
    setVisible(true);
    pUniverse = new VirtualUniverse();
    pLocale = new Locale(pUniverse);
    pView = new View();
    pVPlatform = new ViewPlatform();
    pBGroup_0 = new BranchGroup();
    pTGroup_0 = new TransformGroup();
    /**
     * Construct the ViewBranch
     */
    pView.addCanvas3D(pCanvas3D);
    pView.setPhysicalBody(new PhysicalBody());
    pView.setPhysicalEnvironment(new PhysicalEnvironment());
    pTGroup_0.addChild(pVPlatform);
    pBGroup_0.addChild(pTGroup_0);
    pLocale.addBranchGraph(pBGroup_0);
    pView.attachViewPlatform(pVPlatform);
    
    /**
     * Creating the Content Branch including the Collision...
     */
    pBGroup_1 = new BranchGroup();
    pTGroup_1 = new TransformGroup();
    // Capabilities settings
    pBGroup_1.setCapability(BranchGroup.ALLOW_DETACH);
    // this is for debugging only!
    pBGroup_1.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    /** this is for moving the node
     * pTGroup_1.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
     * pTGroup_1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
     * pTGroup_1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
     * pTGroup_1.setCapability(Group.ALLOW_CHILDREN_EXTEND);
     */
    pTGroup_1.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    pTGroup_1.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    pTGroup_1.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    pAppearance = new Appearance();
    pAppearance.setMaterial(new Material(
    new Color3f(1,0,0), //ambient color
    new Color3f(1,0,0), //emisive color
    new Color3f(1,0,0), //difuse color
    new Color3f(1,1,1), //specular color
    100f));
    pBox=new com.sun.j3d.utils.geometry.Box(0.2f,0.2f,0.2f,pAppearance);
    pT3D_0 = new Transform3D();
    pT3D_1 = new Transform3D();
    pT3D_0.setTranslation(new Vector3d(0,0,-4));
    pT3D_1.rotX(Math.PI/4);
    pT3D_0.mul(pT3D_1);
    pTGroup_1.setTransform(pT3D_0);
    pTGroup_1.addChild(pBox);
    pBGroup_1.addChild(pTGroup_1);
    // Setting the collision  customer 
    pCHandle=new CollisionHandler(pBox);
    pCHandle.setSchedulingBounds(new BoundingSphere(new Point3d(0,0,0),0.4d));
    pTGroup_1.addChild(pCHandle);
    // Live
    pLocale.addBranchGraph(pBGroup_1);
    
    //    setResizable(false);
    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(java.awt.event.WindowEvent evt) {
        exitForm(evt);
      }
    });
    pCanvas3D.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent e) {
        switch (e.getKeyChar()) {
          case 'P':
          case 'p':
            if (!pBGroup_1.isLive()){
              System.out.println("Placing the box");
              pLocale.addBranchGraph(pBGroup_1);
            }
            break;
          case 'R':
          case 'r':
            if (pBGroup_1.isLive()&&pCHandle.isLive()){
              System.out.println("Removing the box");
              // Using Locale.removeBranchGraph or detach has the same effect! :((
              // pLocale.removeBranchGraph(pBGroup_1);
              pBGroup_1.detach();
            }
            break;
          default:
            System.out.println("Wrong key. Press P or R keys!");
        }
      }
    });
    pCanvas3D.requestFocus();
    pack();
  }
  private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
  }
  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    new testCollision().show();
  }
  // Variables declaration
  private VirtualUniverse pUniverse;
  private Canvas3D pCanvas3D;
  private Locale pLocale;
  private View pView;
  private ViewPlatform pVPlatform;
  private TransformGroup pTGroup_0,pTGroup_1;
  private BranchGroup pBGroup_0,pBGroup_1;
  private Transform3D pT3D_0,pT3D_1;
  private Appearance pAppearance;
  private com.sun.j3d.utils.geometry.Box pBox;
  private GraphicsConfigTemplate3D pGTmpl3D;
  private GraphicsDevice pGDev;
  private GraphicsConfiguration pGConf;
  private CollisionHandler pCHandle;
  
  class CollisionHandler extends Behavior {
    
    /** Creates a new instance of CollissionHandler */
    public CollisionHandler(Node pNode) {
      armingNode(pNode);
    }
    /** Initialize should be call after armingNode! Best practice is to first set the node
     * and later to add the  customer  to the scenegraph */
    public void initialize() {
      wakeupOn(pWOr);
    }
    public void processStimulus(java.util.Enumeration e) {
      System.out.println("Debug collision: BINGO!");
      while(e.hasMoreElements()){
        WakeupCriterion pWCriterion = (WakeupCriterion) e.nextElement();
        if (pWCriterion instanceof WakeupOnCollisionEntry){
          //something
        }
        else if (pWCriterion instanceof WakeupOnCollisionExit){
          //something else
        }
      }
      // set next WakeupCriterion
      wakeupOn(pWOr);
    }
    void armingNode(Node pNode) {
      aWCriteria[0]= pWUEnter = new WakeupOnCollisionEntry(pNode,WakeupOnCollisionEntry.USE_GEOMETRY);
      aWCriteria[1]= pWUExit  = new WakeupOnCollisionExit(pNode,WakeupOnCollisionExit.USE_GEOMETRY);
      pWOr=new WakeupOr(aWCriteria);
    }
    private WakeupCriterion[] aWCriteria = new WakeupCriterion[2];
    private WakeupOr pWOr;
    private WakeupOnCollisionEntry pWUEnter;
    private WakeupOnCollisionExit pWUExit;
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
One method that used to work was to introduce a big wait (10000) before removing the branch group. It used to work under linux but it doesn't work anymore under windows.
(Incident Review ID: 186599) 
======================================================================
Posted Date : 2005-12-14 19:38:21.0
Work Around
N/A
Evaluation
This is a duplicate of java.net issue tracker as Issue 193 : https://java3d.dev.java.net/issues/show_bug.cgi?id=193
Posted Date : 2005-12-14 19:38:21.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang