# Newbie question - what am I doing wrong?

Hello everybody,

I’m trying to learn jME, by porting over an old project of mine. Basically, I’m trying to build a hex map (I’m trying to port an old pen and paper boardgame to the 21st century).

My map is made up of hexagons. Each hexagon is made up of 6 TriMesh objects, and each TriMesh contains either one triangle or four triangles (the basic case is if the hex is surrounded by coplanar hexes, then you get six even triangular slices; if you get hills, the hill side of the hexagon is raised and you get the other triangles to build a continuous mesh).

See here for examples of the expected result:

Now, this fragment of code shows how I build a triangle:

```     private void createGeometry()     {         Vector3f[] normals={             new Vector3f(0,0,1),             new Vector3f(0,0,1),             new Vector3f(0,0,1) };         ColorRGBA[] colors={             new ColorRGBA(1,0,0,1),             new ColorRGBA(1,0,0,1),             new ColorRGBA(1,0,0,1) };         // First triangle         if (y_dim[0] == y_dim[6] && y_dim[0] == y_dim[7] && y_dim[0] == y_dim[1])         {             Vector3f[] vertexes={                 new Vector3f(0.0f, y_dim[0], 0.0f),                 new Vector3f(xDimHalf, y_dim[1], -zDim),                 new Vector3f(-xDimHalf, y_dim[6], -zDim) };             Vector2f[] texCoords={                 new Vector2f(0.5f * TC_X_FACTOR, 0.5f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.75f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.25f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR) };             int[] indexes={0,1,2};             m1.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),             BufferUtils.createFloatBuffer(colors),BufferUtils.createFloatBuffer(texCoords),             BufferUtils.createIntBuffer(indexes));             m1.setModelBound(new BoundingBox());             m1.updateModelBound();                         this.attachChild(m1);         }         else         {             Vector3f[] vertexes={                 new Vector3f(0.0f, y_dim[0], 0.0f),                 new Vector3f(xDimQuart, y_dim[0], -zDimHalf),                 new Vector3f(-xDimQuart, y_dim[0], -zDimHalf),                 new Vector3f(xDimQuart, y_dim[0], -zDimHalf),                 new Vector3f(xDimHalf, y_dim[1], -zDim),                 new Vector3f(0.0f, y_dim[7], -zDim),                 new Vector3f(xDimQuart, y_dim[0], -zDimHalf),                 new Vector3f(0.0f, y_dim[7], -zDim),                 new Vector3f(-xDimQuart, y_dim[0], -zDimHalf),                 new Vector3f(-xDimQuart, y_dim[0], -zDimHalf),                 new Vector3f(0.0f, y_dim[7], -zDim),                 new Vector3f(-xDimHalf, y_dim[6], -zDim) };             Vector2f[] texCoords={                 new Vector2f(0.5f * TC_X_FACTOR, 0.5f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.5f * TC_X_FACTOR, 0.5f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.375f * TC_X_FACTOR, 0.75f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.625f * TC_X_FACTOR, 0.75f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.75f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.5f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.625f * TC_X_FACTOR, 0.75f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.5f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.375f * TC_X_FACTOR, 0.75f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.375f * TC_X_FACTOR, 0.75f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.5f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR),                 new Vector2f(0.25f * TC_X_FACTOR, 1.0f * TC_Y_FACTOR + TC_Y_BOTTOM_FACTOR) };             int[] indexes={0,1,2,3,4,5,6,7,8,9,10,11};             m1.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),             BufferUtils.createFloatBuffer(colors),BufferUtils.createFloatBuffer(texCoords),             BufferUtils.createIntBuffer(indexes));               m1.setModelBound(new BoundingBox());             m1.updateModelBound();                         this.attachChild(m1);         }         // other triangles follow     } ```

This method comes from my Hex class which extends Node.

I have written a simple test class, as follows:

``` public class Test1 extends SimpleGame {     private HexBoard board;         protected void simpleInitGame()     {         Node n = new Node();         board.createBoard();         rootNode.setLightCombineMode(LightState.OFF);         Hex h1 = board.getHex(0, 0);         rootNode.attachChild(h1);         Hex h2 = board.getHex(3, 3);         rootNode.attachChild(h2);         Hex h3 = board.getHex(6, 6);         rootNode.attachChild(h3);         Hex h4 = board.getHex(9, 9);         rootNode.attachChild(h4);         Hex h5 = board.getHex(12, 12);         rootNode.attachChild(h5);         Hex h6 = board.getHex(15, 15);         rootNode.attachChild(h6);     }         public static void main(String[] args)     {         try         {             Properties gameProps = new Properties();             try             {                 gameProps.load(new FileInputStream("game.props"));             }             catch (IOException e)             {                 e.printStackTrace();             }             GameConfiguration config = new GameConfiguration();             HexBoard hexBoard = new HexBoard(config.getBoard(), config.getHexProperties(), config.getAppearanceHandler(), config.getUnitHandler());             Test1 app = new Test1();             app.setBoard(hexBoard);             app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);             app.start();         }         catch (Exception ex)         {             Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);         }     }     public HexBoard getBoard()     {         return board;     }     public void setBoard(HexBoard board)     {         this.board = board;     } } ```

The first and last hexagons are flat, while the others are either below water or a mountain. I can't display any non flat hexagon. No matter which one, I always ger this:

``` GRAVE: Exception in game loop java.lang.IllegalArgumentException         at java.nio.Buffer.limit(Buffer.java:249)         at com.jme.renderer.lwjgl.LWJGLRenderer.predrawGeometry(Unknown Source)         at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)         at com.jme.scene.batch.TriangleBatch.draw(Unknown Source)         at com.jme.scene.TriMesh.draw(Unknown Source)         at com.jme.scene.Spatial.onDraw(Unknown Source)         at com.jme.scene.Node.draw(Unknown Source)         at com.jme.scene.Spatial.onDraw(Unknown Source)         at com.jme.scene.Node.draw(Unknown Source)         at com.jme.scene.Spatial.onDraw(Unknown Source)         at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)         at com.jme.app.SimpleGame.render(Unknown Source)         at com.jme.app.BaseGame.start(Unknown Source)         at com.massimilianobussi.hexmaplib.test.Test1.main(Test1.java:64) 15 mars 2008 15:05:05 com.jme.app.BaseSimpleGame cleanup INFO: Cleaning up resources. 15 mars 2008 15:05:05 com.jme.app.BaseGame start INFO: Application ending. ```

What am I doing wrong?

Massimiliano

Maybe your accidently setting something to zero (or NaN) that shouldn't be set to zero or NaN?

Maybe try debugging your hex creation class to see what values a flat hex contains.