Custom mesh + picking = BIHTree Crash. (Fixed)

I’ve made a simple Circle class to outline planets and binary stars orbits that works fine but when those circles are attached to the scene node and iterate through the meshes when picking with a Ray I get a crash in BIHTree.

With no circles there’s no crash, so it’s either the BIHTree or the Circle class.

The picking is quite simple:


CollisionResults cr = new CollisionResults();

sceneNode.collideWith(ray, cr);


The crash dump:


Oct 21, 2011 2:30:34 PM handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]


at java.nio.Buffer.checkIndex(

at java.nio.DirectFloatBufferU.get(

at com.jme3.collision.bih.BIHTree.initTriList(

at com.jme3.collision.bih.BIHTree.<init>(

at com.jme3.collision.bih.BIHTree.<init>(

at com.jme3.scene.Mesh.createCollisionData(

at com.jme3.scene.Mesh.collideWith(

at com.jme3.scene.Geometry.collideWith(

at com.jme3.scene.Node.collideWith(



at com.jme3.input.InputManager.invokeActions(

at com.jme3.input.InputManager.onMouseButtonEventQueued(

at com.jme3.input.InputManager.processQueue(

at com.jme3.input.InputManager.update(



at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(




I’m not sure exactly what could cause this…

The issue is probably with your mesh data…

Here’s the Circle class. It’s loosely based on WireSphere. Care to point me out where the error could be/is? :slight_smile:


public final class Circle extends Mesh {

private final static int samples = 128;

private final static int zSamples = 1;

public Circle(float radius, float lineWidth) {


ShortBuffer ib = BufferUtils.createShortBuffer(samples * 4 + zSamples * samples * 2);

setBuffer(Type.Index, 2, ib);

int curNum = 0;

for (int j = 0; j < 2 + zSamples; j++) {

for (int i = curNum, k = curNum + samples - 1; i < k; i++) {

ib.put((short) i).put((short) (i + 1));


ib.put((short) (curNum + samples - 1)).put((short) curNum);

curNum += samples;







public void updatePositions(float radius) {

VertexBuffer pvb = getBuffer(Type.Position);

FloatBuffer pb;

if (pvb == null) {

pvb = new VertexBuffer(Type.Position);

pb = BufferUtils.createVector3Buffer(samples);

pvb.setupData(Usage.Dynamic, 3, Format.Float, pb);


} else {

pb = (FloatBuffer) pvb.getData();



float rate = FastMath.TWO_PI / (float) samples;

float angle = 0;

for (int i = 0; i < samples; i++){

float x;

float y;

x = radius * FastMath.cos(angle);

y = radius * FastMath.sin(angle);


angle += rate;





Well, it looks to me from a quick read like you are creating a position buffer with 128 entries in it but then indexing into it as if there are 3 times that many.

1 Like


That’ll show me to copy/paste. :smiley:

Thanks Paul.

The bill is in the mail. :wink:

quickly switches number on the mailbox

Sure. Send it my way. :smiley: