Implementing Jbullet-jme in Standard Canvas

I'm having an error like this in my stacktrace, how do I fix this?


Exception in thread "Thread-4" java.lang.NoSuchMethodError: com.bulletphysics.collision.broadphase.OverlappingPairCache.setInternalGhostPairCallback(Lcom/bulletphysics/collision/broadphase/OverlappingPairCallback;)V
   at com.jmex.jbullet.PhysicsSpace.<init>(PhysicsSpace.java:204)
   at com.jmex.jbullet.PhysicsSpace.<init>(PhysicsSjavascript:void(0);pace.java:159)
   at com.jmex.jbullet.PhysicsSpace$1.<init>(PhysicsSpace.java:109)
   at com.jmex.jbullet.PhysicsSpace.getPhysicsSpace(PhysicsSpace.java:109)
   at trials.bulletTrial$1.run(bulletTrial.java:52)
   at java.lang.Thread.run(Unknown Source)



here's my code...

package trials;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.util.prefs.Preferences;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.scene.shape.Box;
import com.jme.system.DisplaySystem;
import com.jme.system.GameSettings;
import com.jme.system.PreferencesGameSettings;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.state.FPSGameState;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.collision.shapes.CollisionShape;
import com.jmex.jbullet.nodes.PhysicsNode;

import canvas.standard.StandardCanvasGame;


public class bulletTrial extends JFrame{
   StandardCanvasGame game;
   Canvas gameCanvas;
   private static GameSettings   settings         = null;
   GameState physicsState;
   public bulletTrial(){
      
      setLayout(new BorderLayout());

      game = new StandardCanvasGame(settings);
      game.start();
      new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               game.waitForSetup();
            } catch (InterruptedException e)
            {
               e.printStackTrace();
            }

            final PhysicsSpace pSpace = PhysicsSpace.getPhysicsSpace();
            physicsState = new FPSGameState(){
               //InputHandler input;
               
               Camera cam;
               {
                  
                  
                  cam = DisplaySystem.getDisplaySystem().getRenderer().getCamera();
                  DisplaySystem.getDisplaySystem().getRenderer().setCamera(cam);
                  
                  cam.setLocation(new Vector3f(0,10,50));
                  cam.lookAt(new Vector3f(0,1,0), Vector3f.ZERO);
                   cam.update();
                  
                   
                    Box box1 = new Box("box", new Vector3f(), 10, 1, 10);
                    PhysicsNode physicsBox = new PhysicsNode(box1,CollisionShape.ShapeTypes.BOX);
                    physicsBox.setLocalTranslation(new Vector3f(0,50,0));
                    rootNode.attachChild(physicsBox);
                    pSpace.add(physicsBox);
                    PhysicsNode node3=new PhysicsNode(new Box("physicsfloor",Vector3f.ZERO,100f,0.2f,100f),CollisionShape.ShapeTypes.MESH,0);
                    node3.setLocalTranslation(new Vector3f());
                    rootNode.attachChild(node3);
                    node3.updateRenderState();
                    pSpace.add(node3);
                   
                    rootNode.updateRenderState();
               
               };
               public void update(float tpf){
                  //input.update(tpf);
                  pSpace.update(tpf);
                  cam.update();
                  rootNode.updateRenderState();
                  rootNode.updateGeometricState(tpf,true);
               }
               public void render(float tpf){
                  super.render(tpf);
                  DisplaySystem.getDisplaySystem().getRenderer().draw(rootNode);
               }
            };
            GameStateManager.getInstance().attachChild(physicsState);
            physicsState.setActive(true);
         }
      }).start();
      getContentPane().add(getGCanvas(), BorderLayout.CENTER);
      this.setSize(settings.getWidth(), settings.getHeight());
      this.setTitle("StandardCanvasGame Test1");
      this.addWindowListener(new java.awt.event.WindowAdapter()
      {
         @Override
         public void windowClosing(java.awt.event.WindowEvent e)
         {
            game.destroy();
         }
      });
      this.setLocationRelativeTo(null);
   }
   
   public Canvas getGCanvas(){
      if (gameCanvas == null)
      {
         gameCanvas = game.getCanvas();
      }
      return gameCanvas;
   }
   public static void main(String[] args) throws InterruptedException
   {
      System.setProperty("jme.stats", "set");
      settings = new PreferencesGameSettings(Preferences.userRoot(), true, "game-defaults.properties");
      GameSettingsPanel.prompt(settings);
      SwingUtilities.invokeLater(new Runnable()
      {
         public void run()
         {
            bulletTrial thisClass = new bulletTrial();
            thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            thisClass.setVisible(true);
         }
      });
   }
}

Seems like you're missing your jbullet libraries in the classpath.

Also, the way you spawn the additional thread in such an "uncontrolled" manner looks problematic, why do you do that?

I've already added the jme-bullet project in my build path, whereas the tests in that project works… am I missing something?

mhelz0001 said:

I've already added the jme-bullet project in my build path, whereas the tests in that project works... am I missing something?

So you added the NetBeans project of the jbullet-jme source as library to the new project? Umm, does that really include the libraries of that project or just its output jar? Try adding the libraries manually. Still, why do you use the additional thread? BasicGame creates a separate Thread for the scenegraph update/render process by itself.

I'll try that… by the way, I'm using the project which I downloaded from the svn repository into my Eclipse IDE… I'll try adding the libraries manually first… then if it fails, I'll get back to you…thanks for the quick replies

ok… seems I can't make that jbullet work on my project… another implementation question then, is there a way to implement jbullet to PhysicsGameState?

Mhelz0001,



If your project compiles, then you have setup your compile-time classpath correctly.



As the problem was encountered you tried to run the project, that indicates the runtime classpath is not setup correctly.

You are going to encounter the same runtime problem however you choose to implement the PhysicsGameState, until you setup the runtime classpath correctly.


I've already had PhysicsGameState working for me… only that I'd have to use jmePhysics2-ode… so the real problem I'm having is in jBullet's classpath… as aforementioned, I can run the tests in the jmetest folder of jbullet-jme in my eclipse ide… however, I can't seem to make it work in my project given that I have already added the whole project folder of jbullet in my classpath

I have already added the whole project folder of jbullet in my classpath


If you have have added the entire jbullet project (jbullet != jbullet-jme) on both the compile time and runtime classpath you will not get the problem from the first post

Exception in thread "Thread-4" java.lang.NoSuchMethodError: com.bulletphysics.collision.broadphase.OverlappingPairCache.setInternalGhostPairCallback(Lcom/bulletphysics/collision/broadphase/OverlappingPairCallback;)V



the real problem I'm having is in jBullet's classpath... as aforementioned


Yes, the problem is that jBullet is not on the classpath being used at runtime by your project. 

I can run the tests in the jmetest folder of jbullet-jme in my eclipse ide... however, I can't seem to make it work in my project


I believe I understand now, you don't have jBullet jars on the classpath at all. The project compiles without problem because you are not directly accessing the jBullet methods (as that is done by jbullet-jme).
The jbullet-jme tests are running fine as the jbullet-jme project has the necessary libraries correctly setup.

All that is need is to add the jbullet jars onto the runtime classpath of your project. There are various ways to achieve this, one of them being to add them as library JARs to your project.

The jars are located within the jbullet-jme project:
    jbullet-jme-read-onlyjbullet-jmelibjBullet

java.lang.NoSuchMethodError means usually that you have a wrong version of a library no ?



could it be that you use a older version of the jbullet jar at runtime ?