An unrecoverable stack overflow has occurred

Well yes I can post a sample code, and maybee someone can find what is causeing this, and how to increase the time before it happens. (around the 771 spawned box, but I need like 2k-3k of physic objects (most of the sleeping so it would run performance wise))

import java.awt.Dimension;
import java.awt.Toolkit;

import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.system.DisplaySystem;
import com.jme.system.GameSettings;
import com.jme.system.PropertiesGameSettings;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.Timer;
import com.jmex.physics.PhysicsDebugger;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.callback.GenericCallback;
import com.jmex.physics.impl.ode.OdePhysicsSpace;

public class test extends FixedLogicrateGame {
   public static void main(String[] args){
      new test().start();
   private Timer timer = Timer.getTimer(); //this is needed!
   static private Node Rootnode = new Node();
   private PhysicsSpace physicsSpace;
   private Camera cam;

   private int lastspawn;
   final static SocketAddress reliable = new InetSocketAddress((InetAddress)null,27015);
   static public Node Getrootnode(){
      return Rootnode;
   protected void initGame() {

      physicsSpace = PhysicsSpace.create();
      OdePhysicsSpace odephysicsSpace = (OdePhysicsSpace) physicsSpace;
      Box floor = new Box("floor",new Vector3f(0,0,0),10,1,10);
      StaticPhysicsNode florrnode = physicsSpace.createStaticNode();
      florrnode.setLocalTranslation(0,-10, 0);
      Box roof = new Box("roof",new Vector3f(0,0,0),10,1,10);
      StaticPhysicsNode roofnode = physicsSpace.createStaticNode();
      roofnode.setLocalTranslation(0,+10, 0);

        physicsSpace.getContactCallbacks().add(new AdvContactCallback());

   protected void initSystem() {
   private void BasicInit() {
      display = DisplaySystem.getDisplaySystem("LWJGL");
   //   display.setMinSamples(2);
      display.createWindow(settings.getWidth(),settings.getHeight(), 32, 120,false);
      display.setTitle("New Horizons (Loading)");
      PositionWindow();//needs the fields display and mysettings!!
      cam = display.getRenderer().createCamera(display.getWidth(),display.getHeight());
      Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
      Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
      Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
      Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
      cam.setFrame(loc, left, up, dir);
      timer = Timer.getTimer();
      KeyBindingManager.getKeyBindingManager().set("spawn", KeyInput.KEY_G);
   protected void reinit() {
      // TODO Auto-generated method stub

   protected void render(float percentWithinTick) {
      Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
      //PhysicsDebugger.drawPhysics(physicsSpace, renderer);

   protected void update(float interpolation) {
      Rootnode.updateGeometricState(1f/60f, true);
      //if (KeyBindingManager.getKeyBindingManager().isValidCommand("spawn", true)) {
         if (lastspawn > 1){
            new PhysEntity(physicsSpace,PhysEntity.GetFreeNetworkId());
            lastspawn = 0;
      lastspawn ++;

   protected GameSettings getNewSettings() {
      return new PropertiesGameSettings(".");

   protected void cleanup() {
      // TODO Auto-generated method stub
   private void PositionWindow() {
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Dimension scrnsize = toolkit.getScreenSize();
      int x = 1000;
      int y = 600;
      if(scrnsize.width-display.getWidth() < x){
         x = scrnsize.width-display.getWidth();
      if(scrnsize.height-display.getHeight() < y){
         y = scrnsize.height-display.getHeight();

   protected void cameraPerspective() {
      cam.setFrustumPerspective(45.0f, (float) display.getWidth()
            / (float) display.getHeight(), 1, 400000000);//Waring may lag, large distance rendering!

import java.util.ArrayList;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.concurrent.Callable;

import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.util.GameTaskQueueManager;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.callback.GenericCallback;
import com.jmex.physics.callback.IGeneralCallbackable;
import com.jmex.physics.material.Material;

public class PhysEntity extends Node{
   private static final long serialVersionUID = 1L;
   private DynamicPhysicsNode physobject;
   static private HashMap<Integer,PhysEntity> objectsbynid = new HashMap<Integer,PhysEntity>();
   private Box box;
   private int NetworkId;
   private boolean fullupdate = false; //initial full update!
   private PhysEntity myself;
   static public PhysEntity GetbyNetworkId(int id){
      return objectsbynid.get(id);
   static public int GetFreeNetworkId(){
      int index = 0;
      boolean found = false;
         Object possible = objectsbynid.get(index);
         if(possible == null){
            found = true;
      System.out.println("Free id = " + index);
      return index;
   PhysEntity(PhysicsSpace physicsSpace,int NetworkId){
      box = new Box("box",new Vector3f(0,0,0),1,1,1);
      physobject = physicsSpace.createDynamicNode();
      physobject.AddForce(new Vector3f(0,1000,0));
      myself = this;
      this.NetworkId = NetworkId;

   public DynamicPhysicsNode GetPhysicObject(){
      return physobject;

With too many collissions at a time, there will be a stackoverflow at some point.

You can try to increase the stacksize, but you will propably also run into performace problems.

You need to limit the collisions somehow, and put physic object to rest when they don't move.;

There is also a auto rest threshold you can set in the PhysicsSpace.setAutoRestThreshold().

  -Xss<size>   set maximum native stack size for any thread
  -Xoss<size>   set maximum Java stack size for any thread. Note: This option is useless with HotSpot as HotSpot doesn't have separate native and Java stacks.
  -Xms<size>   set initial Java heap size
  -Xmx<size>   set maximum Java heap size

Hm, dos nto help, even with extreme settings like these


it crashes at the same Object.

Also my objets are not coliding, it's just a few hundret of boxes, flying wihtout gravity into the void
(as a network test, wich so far works fine when using less than 700 boxes)