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))



test.java


import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

import com.jme.app.FixedLogicrateGame;
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.contact.AdvContactCallback;
import com.jmex.physics.impl.ode.OdePhysicsSpace;



public class test extends FixedLogicrateGame {
   
   public static void main(String[] args){
      new test().start();
      
   }
   
   @SuppressWarnings("unused")
   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;
   }
   
   @Override
   protected void initGame() {
      this.display.moveWindowTo(1024,600);


      
      physicsSpace = PhysicsSpace.create();
      physicsSpace.setAutoRestThreshold(0.1f);
      OdePhysicsSpace odephysicsSpace = (OdePhysicsSpace) physicsSpace;
      odephysicsSpace.setStepInteractions(1);
      Rootnode.setRenderState(DisplaySystem.getDisplaySystem().getRenderer().createZBufferState());
      
         
      Box floor = new Box("floor",new Vector3f(0,0,0),10,1,10);
      StaticPhysicsNode florrnode = physicsSpace.createStaticNode();
      florrnode.setLocalTranslation(0,-10, 0);
      florrnode.attachChild(floor);
      florrnode.generatePhysicsGeometry(true);
      Rootnode.attachChild(florrnode);
      
      Box roof = new Box("roof",new Vector3f(0,0,0),10,1,10);
      StaticPhysicsNode roofnode = physicsSpace.createStaticNode();
      roofnode.setLocalTranslation(0,+10, 0);
      roofnode.attachChild(roof);
      roofnode.generatePhysicsGeometry(true);
      Rootnode.attachChild(roofnode);
      
      Rootnode.updateRenderState();

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

   @Override
   protected void initSystem() {
      BasicInit();
   }
   
   private void BasicInit() {
      settings.setHeight(600);
      settings.setWidth(800);
      display = DisplaySystem.getDisplaySystem("LWJGL");
      display.setMinDepthBits(24);
      display.setMinStencilBits(2);
      display.setMinAlphaBits(8);
   //   display.setMinSamples(2);
      display.createWindow(settings.getWidth(),settings.getHeight(), 32, 120,false);
      
      display.setVSyncEnabled(false);
      display.setTitle("New Horizons (Loading)");
      PositionWindow();//needs the fields display and mysettings!!
      cam = display.getRenderer().createCamera(display.getWidth(),display.getHeight());
      display.getRenderer().setBackgroundColor(ColorRGBA.black.clone());
      cameraPerspective();
      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);
      cam.update();
      timer = Timer.getTimer();
      display.getRenderer().setCamera(cam);
      KeyBindingManager.getKeyBindingManager().set("spawn", KeyInput.KEY_G);
   }
   
   @Override
   protected void reinit() {
      // TODO Auto-generated method stub
      
   }

   @Override
   protected void render(float percentWithinTick) {
      Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
      renderer.clearBuffers();
      renderer.draw(Rootnode);
      //PhysicsDebugger.drawPhysics(physicsSpace, renderer);
   }

   @Override
   protected void update(float interpolation) {
      GameTaskQueueManager.getManager().getQueue(GameTaskQueue.UPDATE).execute();
      
      Rootnode.updateGeometricState(1f/60f, true);
      
      //if (KeyBindingManager.getKeyBindingManager().isValidCommand("spawn", true)) {
         if (lastspawn > 1){
            new PhysEntity(physicsSpace,PhysEntity.GetFreeNetworkId());
            lastspawn = 0;
         }
      //}
      lastspawn ++;
      physicsSpace.update(1f/60f);
   }

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

   @Override
   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();
      }
      display.moveWindowTo(x,y);
   }

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



PhysEntity.java


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.contact.PendingContact;
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;
      while(!found){
         Object possible = objectsbynid.get(index);
         if(possible == null){
            found = true;
         }
         else{
            index++;
         }
      }
      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);
      box.setRandomColors();
      physobject = physicsSpace.createDynamicNode();
      physobject.attachChild(box);
      physobject.setMaterial(Material.ICE);
      physobject.SetMass(100);
      physobject.setAffectedByGravity(false);
      physobject.generatePhysicsGeometry(true);
      physobject.AddForce(new Vector3f(0,1000,0));
      myself = this;
      this.attachChild(physobject);
      this.NetworkId = NetworkId;
      objectsbynid.put(NetworkId,this);
      
      test.Getrootnode().attachChild(this);
   }

   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. dynamicPhysicsNode.rest();

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
  -XX:MaxDirectMemorySize=<value> 

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



-Xss=1024m
-Xoss=1024m
-Xms=1024m
-Xmx=102m
-XX:MaxDirectMemorySize=1024m


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)