0

I am trying to put a collision-shape onto my model. But everytime I init the game, I get an NegativeArraySizeException.

private void createSoundBit(float x, float y, float z)
    {
        Spatial npc1 = assetManager.loadModel("Models/sound/sound.j3o");
        npcNode.attachChild(npc1);
        CollisionShape noteshape = CollisionShapeFactory.createDynamicMeshShape(npc1);
        npcRigid = new RigidBodyControl(noteshape,123.0f);
        npcRigid.setFriction(0f);
        npcRigid.setMass(60f);
        npcRigid.setPhysicsLocation(new Vector3f(x,y,z));
        collmanager = new CollManager();
        getPhysicsSpace().addCollisionListener(collmanager);

        npc1.addControl(npcRigid);
        bulletAppState.getPhysicsSpace().add(npcRigid);
        rootNode.attachChild(npcNode);
    }

I don't know why it happens

Stacktrace:

java.lang.NegativeArraySizeException
    at com.jme3.bullet.collision.shapes.HullCollisionShape.getPoints(HullCollisionShape.java:71)
    at com.jme3.bullet.collision.shapes.HullCollisionShape.<init>(HullCollisionShape.java:24)
    at com.jme3.bullet.util.CollisionShapeFactory.createSingleDynamicMeshShape(CollisionShapeFactory.java:241)
    at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:112)
    at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:94)
    at com.jme3.bullet.util.CollisionShapeFactory.createDynamicMeshShape(CollisionShapeFactory.java:188)
    at Main.createSoundBit(Main.java:206)
    at Main.simpleInitApp(Main.java:83)
    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
    at java.lang.Thread.run(Thread.java:722)
Luzius L
  • 157
  • 1
  • 9
  • 1
    The Stacktrace would be useful. – MrSmith42 Jan 26 '13 at 15:32
  • I see no array creation / access in your code. => the array must be in an other piece of code. – MrSmith42 Jan 26 '13 at 15:34
  • In HullCollisionShape.getPoints method an array might have been initialized with negative value size . It might be due to either you passing negative value to the size declaration of array or you might have hard coded. – Vishal K Jan 26 '13 at 20:13

1 Answers1

0

For me it can be one of two things: your file sound.j3o is corrupted or there is a bug in jmonkeyengine. Try to load some other file and see what's happening. Part of source where is a problem:

FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
int components = mesh.getVertexCount() * 3;
float[] pointsArray = new float[components];
// ...

So, looks like mesh.getVertexCount() returned negative value.

partlov
  • 13,789
  • 6
  • 63
  • 82
  • I can load two other models and they work just fine. The working models are cylinder-shaped and this corrupt-model is a music note. – Luzius L Jan 26 '13 at 20:51