Adding BulletAppState to statemanager throws error from native code

When I try to add an instance of BulletAppState to the stateManager I get the following error,

Bullet-Native: Initializing java classes
Execution protection violation
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x20000000, pid=12088, tid=5576
#
# JRE version: Java(TM) SE Runtime Environment (8.0_77-b03) (build 1.8.0_77-b03)
# Java VM: Java HotSpot(TM) Client VM (25.77-b03 mixed mode windows-x86 )
# Problematic frame:
# C  0x20000000
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Irfan\jME Projects\TestGame\hs_err_pid12088.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
AL lib: (EE) alc_cleanup: 1 device not closed
C:\Users\iamcr\AppData\Roaming\.jmonkeyplatform\3.1.0-beta1-SNAPSHOT\var\cache\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

Here is the code I am running,

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

public class Main extends SimpleApplication{

    public static void main(String[] args) {
        Main app = new Main();
        app.showSettings = false;
        app.start();
        
    }
    
    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1); 
        Geometry boxGeom = new Geometry("Box", b);  
        Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");  
        boxMat.setColor("Color", ColorRGBA.Blue);   
        boxGeom.setMaterial(boxMat);                
        rootNode.attachChild(boxGeom);              
        
        BulletAppState bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);  // this line triggers the error
        RigidBodyControl boxRigidControl = new RigidBodyControl(0f);
        boxGeom.addControl(boxRigidControl);
        bulletAppState.getPhysicsSpace().add(boxGeom);
        
    }

    @Override
    public void simpleUpdate(float tpf) {
    }

    @Override
    public void simpleRender(RenderManager rm) {
    }
}

How can I solve this problem? It looks the error log doesn’t say a lot.

…guys…a little help here…

Yes, I’ve read that thread, but I couldn’t follow what was going on.

Regardless I’ve found a solution.

  1. Remove, jme3-bullet-3.1.0-beta1.jar from your project.

  2. Download the latest jME(31st July), and compile it(run build.gradle).

  3. Add the jME3-jbullet-3.2.0.jar from compiled_directory/jme3-jbullet/build/libs to your project.

  4. Add jbullet.jar and stack-alloc.jar to your project from compiled_directory/lib

  5. Add vecmath-1.3.1.jar found under jMP installation directory. For me the path is, C:\Program Files (x86)\jmonkeyplatform\jmonkeyplatform\libs\vecmath-1.3.1.jar

Now my program runs.

But, what was the problem here?

jme3-bullet is to be used with native bullet. From your last post and your error log I think you we’re missing the jme3-native-bullet library, which would explain the crash because I can’t see anything wrong with your code above.

I ran the build.gradle file inside jme3-bullet-native folder, and it compiles jme3-bullet-3.2.0-SNAPSHOT.jar and jme3-bullet-native-3.2.0-SNAPSHOT.jar, and I used them instead of jme3-bullet-3.1.0-beta1.jar and jme3-bullet-3.1.0-beta1.jar.

But I get similar error,

Bullet-Native: Initializing java classes
Execution protection violation
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x20000000, pid=12368, tid=13592
#
# JRE version: Java(TM) SE Runtime Environment (8.0_77-b03) (build 1.8.0_77-b03)
# Java VM: Java HotSpot(TM) Client VM (25.77-b03 mixed mode windows-x86 )
# Problematic frame:
# C  0x20000000
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Irfan\jME Projects\test\hs_err_pid12368.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Hi @iamcreasy!

JME has 2 Bullet Physics implementations: JBullet and native bullet.

JBullet requires jme3-jbullet.jar, Jbullet.jar, stack-alloc.jar. Your exception will not be shown, if you use JBullet, but I think eventually this library support will be dropped in future JME versions.

Native bullet uses code, written in C++. You need to compile this code to dll, if we talk about Windows platform. If you want to use native bullet, you need to use jme3-bullet.jar and jme3-bullet-native.jar. Latter file contains dll files. Your exception currently happens, if you use native bullet x86. If you use x64 it does not happen. Bug was fixed, and if you recompile C++, you will not get the exception in case of x86.

When you rebuild jme3-bullet-native, C++ files won’t be compiled by default, and will be got from the precompiled dlls, so you will get the same exception as in your post. You can enable dll recompilation, if you change buildNativeProjects property to true in file gradle.properties. This parameter was created to prevent dll recompilation for every build: dll files occupy much space and will pollute the repository. And also not everyone has C++ environment set up. They are compiled time to time and put to the repository though. But current precompiled bulletjme.dll has a bug.

If you want to recompile dll, you need to set up environment: MS Visual studio or Mingw: you can check possible options inside jme3-bullet-native/build.gradle. Note, that mingw requires --kill-at option, otherwise dll functions will get wrong signatures. I think such issue will not be present in case of MS Visual studio.

So, your option is either use JBullet or rebuild Native bullet, but you need to set up C++ compilation environment.

2 Likes