Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (714)
Games in Android Showcase (214)
games submitted by our members
Games in WIP (788)
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 1194 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  
You cannot reply to this message, because it is very, very old.

CopyableCougar4 (114 views)
2017-03-24 15:39:42

theagentd (96 views)
2017-03-24 15:32:08

Rule (157 views)
2017-03-19 12:43:22

Rule (145 views)
2017-03-19 12:42:17

Rule (149 views)
2017-03-19 12:36:21

theagentd (161 views)
2017-03-16 05:07:07

theagentd (159 views)
2017-03-15 22:37:06

theagentd (134 views)
2017-03-15 22:32:18

theagentd (128 views)
2017-03-15 22:31:11

ral0r2 (155 views)
2017-03-03 11:52:41
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 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!