Issues using Cubes library

Hi there, I am making a game that has a Minecraft-like world generation. No, that’s not a Minecraft clone, I only need the world gen made in cubes :smiley: . For that i decided to use the Cubes library, that seemed quite good. Said well: seamed. It has a lot of problems. Just to have a bigger control on the code, i based my project on the Cubes source code, and not imported it just has a library. The problem is: Cubes’s world gen is really slow, really. to perform it, I decided to generate a single chunk at the start, and generating new chunks each time the player is at a certain distance for the world end. This could made the world teorically infinite. Here we make two big problems, one bigger, one shorter. Starting from the shorter:

  1. I can’t generate any chunk in negative positions, this make the world not infinite.

  2. The bigger one, and the most annoying:
    When I generate a new chunk, I can’t destroy any block placed by the world generation anymore. When I try to destroy that block, the game crashes and return the following error: " Uncaught exception thrown in Thread[LWJGL Renderer Thread, 5, main] ArrayIndexOutOfBuondsException: 1".

Googling for a while, I found that the ArrayIndexOutOfBuondsException happens when you try to operate on a not existing array cell.
OK, returning to what happens in my game:
If I try to place a block, I can. But before the game places something like “a mask” on the block I’m placing another block on.

That a very big deal, and I don’t know hot wot solve, it’s from some days I try, with any results. Can please someone help me? :smiley:

Thanks anyway.

We’re going to need some code before we can help you out.

  1. The bigger one, and the most annoying:
    When I generate a new chunk, I can’t destroy any block placed by the world generation anymore. When I try to destroy that block, the game crashes and return the following error: " Uncaught exception thrown in Thread[LWJGL Renderer Thread, 5, main] ArrayIndexOutOfBuondsException: 1".

Could we see your code for destroying blocks?

Sure I can, i don’t know If you ever used the cubes Library, but i just used the pre-existing method BlockTerrainContro.removeblock(Vector3Int location). The only thing I added, was controlling if the player was at certain distance from the block, but it’s not influencing in any way, because I used and if statement to check the position, if the player is not in a range of 3 blocks from the position you want to place or remove the block on, it will return a System.out.println(“You can’t remove that block there”) or “you can’t place a block there”, depending on the action.

A thing a forgot to say is that the game only crashes if I generate a new chunk. If I don’t generate any new chunk, the whole thing goes well

Another thing I forgot to say was that to create a new chunk, is re-use the initBlockTerrain() method, but I only change the position of the chunk to not generate two chunks in the same position

I am not really familiar with that library. Maybe it uses arrays instead of Vectors so you can’t dynamically manipulate it? I’m sorry I can’t be of much help :frowning:

The library uses its own Vector, that’s Vector3Int, not Vector3f. Uses ints instead of floats

I mean maybe the memory allocation for the chunk generation is an array (which I doubt because it would be extremely silly)

I don’t think so, the error message says that the errore is in LWJGL thread, not in my code. Here is the error message in console:

dic 09, 2016 3:17:05 PM com.jme3.app.Application handleError
Grave: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ArrayIndexOutOfBoundsException: 1
at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:170)
at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:143)
at com.bulletphysics.collision.shapes.OptimizedBvh.setInternalNodeAabbMax(OptimizedBvh.java:94)
at com.bulletphysics.collision.shapes.OptimizedBvh.buildTree(OptimizedBvh.java:507)
at com.bulletphysics.collision.shapes.OptimizedBvh.build(OptimizedBvh.java:318)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.(BvhTriangleMeshShape.java:80)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.(BvhTriangleMeshShape.java:63)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createShape(MeshCollisionShape.java:122)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:77)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.(MeshCollisionShape.java:65)
at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:214)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:171)
at com.jme3.bullet.control.RigidBodyControl.createCollisionShape(RigidBodyControl.java:150)
at com.jme3.bullet.control.RigidBodyControl.setSpatial(RigidBodyControl.java:125)
at com.jme3.scene.Spatial.addControl(Spatial.java:602)
at com.cubes.test.Main$1.onSpatialUpdated(Main.java:133)
at com.cubes.BlockTerrainControl.updateSpatial(BlockTerrainControl.java:194)
at com.cubes.BlockTerrainControl.controlUpdate(BlockTerrainControl.java:67)
at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:112)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
at com.jme3.scene.Node.updateLogicalState(Node.java:145)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

The cubes library has no concept for ‘chunks’ as far as i know, it is intended to be used for a small world with fixed size.
I’m assuming you are creating multiple worlds and are simply using the methods of one world to manipulate them, thus getting an ArrayIndexOutOfBoundsException when acting on a different world than the one you are calling the methods of.
If you want to have infinite terrain you will have to get that somewhere else or write your own.

(edit: let me correct that, what i meant is not that it does not have chunks, but that it has no dynamic chunk loading/unloading and the terrains are not meant as chunks as you are using them. Changes nothing for my last sentence though)

Oh, thanks. The problem is that I don’t know how to do that, I don’t have enough knowledge

No offense, but if you had to google what ArrayIndexOutOfBoundsException is, you should probably learn java properly first.

I searched, and i said it in the first message of the thread. Read properly first. I just don’t know how to say in english