java.lang.ArrayIndexOutOfBoundsException

I extended JPanel to add a Java3D panel to a SWING frame, then to do some optimizations I changed it to extending Canvas3D, and somehow that broke my texture binding!

Here’s the code:


51        QuadArray map = new QuadArray (4,QuadArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
52        map.setCoordinate(0, new Point3f(-(width/2f), -(height/2f), -6.0f));
53        map.setCoordinate(1, new Point3f( (width/2f), -(height/2f), -6.0f));
54        map.setCoordinate(2, new Point3f( (width/2f),  (height/2f), -6.0f));
55        map.setCoordinate(3, new Point3f(-(width/2f),  (height/2f), -6.0f));
56
57        map.setTextureCoordinate(GeometryArray.TEXTURE_COORDINATE_2, 0, new TexCoord2f(0.0f,0.0f));
58        map.setTextureCoordinate(GeometryArray.TEXTURE_COORDINATE_2, 1, new TexCoord2f(1.0f,0.0f)); 
59        map.setTextureCoordinate(GeometryArray.TEXTURE_COORDINATE_2, 2, new TexCoord2f(1.0f,1.0f));
60        map.setTextureCoordinate(GeometryArray.TEXTURE_COORDINATE_2, 3, new TexCoord2f(0.0f,1.0f));

…and here is the StackTrace:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 64 at javax.media.j3d.GeometryArrayRetained.setTextureCoordinates(GeometryArrayRetained.java:4798) at javax.media.j3d.GeometryArray.setTextureCoordinate(GeometryArray.java:2034) at Map.createSceneGraph(Map.java:57) at Map.init(Map.java:107) at Map.<init>(Map.java:41) at Main.BuildGUI(Main.java:115) at Main.<init>(Main.java:56) at Main.main(Main.java:34)

:-
Well, I fixed it by using


50        QuadArray map = new QuadArray (4,QuadArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
51        map.setCoordinate(0, new Point3f(-(width/2f), -(height/2f), -6.0f));
52        map.setCoordinate(1, new Point3f( (width/2f), -(height/2f), -6.0f));
53        map.setCoordinate(2, new Point3f( (width/2f),  (height/2f), -6.0f));
54        map.setCoordinate(3, new Point3f(-(width/2f),  (height/2f), -6.0f));
55
56        map.setTextureCoordinate(0, new Point2f(0.0f,0.0f));
57        map.setTextureCoordinate(1, new Point2f(1.0f,0.0f)); 
58        map.setTextureCoordinate(2, new Point2f(1.0f,1.0f));
59        map.setTextureCoordinate(3, new Point2f(0.0f,1.0f));

I have no idea why this worked, but the setTextureCoordinate(int, Point2f) is deprecated, so it may not work for much longer! ???