Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (778)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Array index exception caused by TextureUnitState??  (Read 1502 times)
0 Members and 1 Guest are viewing this topic.
Offline victorwang

Senior Newbie

i will be uberjavaman

« Posted 2004-08-18 03:24:12 »

I'm following the getting started guide (my code isn't exactly what is shown in the guide though) and I have a little program that uses all the functions taught up until multitexturing, but when I added multitexturing with the TextureUnitState[] array (it's the only array I explicitly use in the program), the program fails to run, giving an ArrayIndexOutOfBoundsException.  I've tried increasing the TextureUnitState[] array size by one during initalization and then adding a dummy TextureUnitState, but that doesn't work either.  Even though there are 2 or 3 objects in the array, index 1 is considered out of bounds.  This to me is very odd, and I don't know what I have done wrong.  Could someone please tell me what this is caused by?  Thanks.

Here is the Xith3DTest constructor, where the problem should lie.  At the very end is the exception I get from the program.

     public Xith3DTest() {
         VirtualUniverse universe = new VirtualUniverse();

         View view = new View();

         Locale locale = new Locale();

         BranchGroup scene = new BranchGroup();

         translate = new Transform3D();
         objTranslate = new TransformGroup(translate);

         rotate = new Transform3D();
         objRotate = new TransformGroup(rotate);

         Texture2D textureCube1, textureCube2 = null;
         TextureLoader tl = new TextureLoader();
         TextureUnitState[] textures = new TextureUnitState[2];
         textures[0] = new TextureUnitState((Texture2D)tl.getMinMapTexture("wormhole1.gif"), null, null);
         textures[1] = new TextureUnitState((Texture2D)tl.getMinMapTexture("wormhole2.gif"), null, null);
         Geometry g = Cube.createCubeViaTriangles(0, 0, 0, 1, false);
         Appearance a = new Appearance();
         Shape3D sh0 = new Shape3D(g, a);
         Shape3D sh1 = new Shape3D(createTriangle());

         Shape3D sh2 = new Shape3D(createCross());

         Shape3D sh3 = new Shape3D(createXPoints());

         Shape3D sh4 = new Shape3D(createQuad());


         RenderPeer rp = new RenderPeerImpl();
         CanvasPeer cp = rp.makeCanvas(null, 800, 600, 32, false);
         Canvas3D canvas = new Canvas3D();
         cp.getComponent().addKeyListener(new KeyAdapter() {
             public void keyPressed(KeyEvent e) {
                 switch(e.getKeyCode()) {
                       case KeyEvent.VK_UP            :      rotXtemp += 0.05;
                                                                 isRotationScheduled = true;
                       case KeyEvent.VK_DOWN      :      rotXtemp -= 0.05;
                                                                       isRotationScheduled = true;
                       case KeyEvent.VK_LEFT      :      rotYtemp += 0.05;
                                                                       isRotationScheduled = true;
                       case KeyEvent.VK_RIGHT      :      rotYtemp -= 0.05;
                                                                       isRotationScheduled = true;
             public void keyReleased(KeyEvent e) {
                   int key = e.getKeyCode();
                   if(            key == KeyEvent.VK_UP
                             ||       key == KeyEvent.VK_RIGHT
                             ||      key == KeyEvent.VK_DOWN
                             ||      key == KeyEvent.VK_LEFT) {
                         rotX = rotXtemp;
                         rotY = rotYtemp;

             public void keyTyped(KeyEvent e) {
                 switch(e.getKeyCode()) {
                       case KeyEvent.VK_ESCAPE      :      System.exit(0); break;
         Toolkit.getDefaultToolkit().addAWTEventListener(new EventListener(),      AWTEvent.KEY_EVENT_MASK
                                                                                                                     | AWTEvent.MOUSE_EVENT_MASK
                                                                                                                       | AWTEvent.MOUSE_MOTION_EVENT_MASK);

                 new Vector3f(0,0,2f),
                 new Vector3f(0,0,0),
                 new Vector3f(0,1,0));

         while(true) {
               if(isRotationScheduled) {


java.lang.ArrayIndexOutOfBoundsException: 1
     at com.xith3d.scenegraph.GeometryArray.getTexCoordData(
     at com.xith3d.render.jogl.ShapeAtomPeer.setupTextureCoords(
     at com.xith3d.render.jogl.ShapeAtomPeer.setupTextureUnit(
     at com.xith3d.render.jogl.ShapeAtomPeer.renderAtom(
     at com.xith3d.render.CanvasPeerBase.render(
     at com.xith3d.render.jogl.CanvasPeerImpl.drawBin(
     at com.xith3d.render.jogl.CanvasPeerImpl.display(
     at com.xith3d.render.jogl.CanvasPeerImpl.render(
     at com.xith3d.scenegraph.View.renderOnce(
     at com.xith3d.scenegraph.View.renderOnce(
     at Xith3DTest.<init>(
     at Xith3DTest.main(

Offline JoyrexJ9

Senior Newbie

Losing my mind...

« Reply #1 - Posted 2004-08-19 18:34:35 »

I encountered the same problem, when layering two textures.

It's because the Geometry you are trying to texture only has one set of texture coords. You require 1 set of texture coords per TextureUnitState.

The code that creates the Geometry would need a extra call to setTextureCoordinates, something like...
float[] texCoords = 
 // Your coords here
quad_data.setTextureCoordinates(0, offset, texCoords); // texture one
quad_data.setTextureCoordinates(1, offset, texCoords); // texture two

Where quad_data is a QuadArray or similar sub-class of Geometry
They do seem to have omitted mentioning this in the tutorial, which I'm sure has caught out many other people

Dungeon Engine -
Offline victorwang

Senior Newbie

i will be uberjavaman

« Reply #2 - Posted 2004-08-20 00:36:57 »

Yay thanks.  What I did was I just copied the createCubeViaTriangles() used in one of the official test classes and pasted it into my source and used that local one instead of the createCubeViaTriangles() in the Cube class.  It then worked for whatever reason.  But your way of doing it is the proper way Cheesy.  It should be added to the guide, which I find often leaves out a lot...

Pages: [1]
  ignore  |  Print  

hadezbladez (359 views)
2018-11-16 13:46:03

hadezbladez (192 views)
2018-11-16 13:41:33

hadezbladez (362 views)
2018-11-16 13:35:35

hadezbladez (90 views)
2018-11-16 13:32:03

EgonOlsen (2192 views)
2018-06-10 19:43:48

EgonOlsen (2227 views)
2018-06-10 19:43:44

EgonOlsen (1384 views)
2018-06-10 19:43:20

DesertCoockie (2022 views)
2018-05-13 18:23:11

nelsongames (1674 views)
2018-04-24 18:15:36

nelsongames (2312 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!