BatchNode gives inconsistent IndexOutOfBoundExceptions

I noticed this while working with a more complex set of geometries (and would get an exception on every run) so I made a simple test case, which seems to produce the problem four out of five times.



[java]

public class TestBatchPicking extends SimpleApplication {



/**

*

/

public TestBatchPicking() {

}



/
(non-Javadoc)

  • @see com.jme3.app.SimpleApplication#simpleInitApp()

    */

    @Override

    public void simpleInitApp() {

    BatchNode batchNode = new BatchNode("batch");





    Box box = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);

    Geometry boxGeom = new Geometry("Box", box);

    boxGeom.setMaterial(createColoredMaterial(ColorRGBA.Red, false));

    batchNode.attachChild(boxGeom);



    Sphere sphere = new Sphere(5, 5, 1);

    Geometry sphereGeom = new Geometry("Sphere", sphere);

    sphereGeom.setMaterial(createColoredMaterial(ColorRGBA.Blue, false));

    batchNode.attachChild(sphereGeom);



    batchNode.batch();



    rootNode.attachChild(batchNode);

    System.out.println("Scene built");

    }



    private Material createColoredMaterial(ColorRGBA color, boolean lit){

    if(lit){

    Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");

    material.setBoolean("UseMaterialColors", true);

    material.setColor("Diffuse", color);

    material.setColor("Ambient", color);

    material.setColor("Specular", color);

    return material;

    }

    else{

    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    material.setColor("Color", color);

    return material;

    }

    }



    /**
  • @param args

    */

    public static void main(String[] args) {

    TestBatchPicking tbp = new TestBatchPicking();

    tbp.start();

    }



    }

    [/java]
1 Like

Fixed and committed, thanks :wink:

1 Like

No sir, thank you :slight_smile: