Crashes when loading/rendering ogrexml

Hm actually after puzzling a bit around it seems as There is a problem with loading this model, can anyone tell me where the problem is?





http://empirephoenix.de/models.rar

dunno, actually it's the example mech from deled just exporter with the ogrexml exporter, thats why I wonderd why it does not work correctly ^^ (I only wanted to grab a simple test model without much work actually)



randomly either this one:


java.lang.NullPointerException
   at com.jme3.renderer.lwjgl.LwjglRenderer.clearTextureUnits(LwjglRenderer.java:1292)
   at com.jme3.renderer.lwjgl.LwjglRenderer.renderMeshDefault(LwjglRenderer.java:1671)
   at com.jme3.renderer.lwjgl.LwjglRenderer.renderMesh(LwjglRenderer.java:1678)
   at com.jme3.material.Material.render(Material.java:555)
   at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:238)
   at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:100)
   at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:139)
   at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:347)
   at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:447)
   at com.jme3.renderer.RenderManager.render(RenderManager.java:464)
   at com.jme3.app.SimpleApplication.update(SimpleApplication.java:145)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:116)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:166)
   at java.lang.Thread.run(Unknown Source)



or this one:


java.lang.ArrayIndexOutOfBoundsException: 16
   at com.jme3.renderer.IDList.moveToNew(IDList.java:26)
   at com.jme3.renderer.lwjgl.LwjglRenderer.setTexture(LwjglRenderer.java:1262)
   at com.jme3.material.Material.render(Material.java:518)
   at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:238)
   at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:100)
   at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:142)
   at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:323)
   at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:447)
   at com.jme3.renderer.RenderManager.render(RenderManager.java:461)
   at com.jme3.app.SimpleApplication.update(SimpleApplication.java:145)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:116)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:166)
   at java.lang.Thread.run(Unknown Source)



I load the models in a different thread, but attach them only in the OpenGlone, also this only happens in my main project, while a simple test case, using the exact same procedure works fine. After spending 6+ hours on this I'm near to giving up.

If anyone want the full source, I can of course upload it somewhere.

Any particular error being printed out?



It looks like you have multiple submeshes, which could be a little weird, but I believe multiple meshes are supported, so idk.  :?

Do you attach them in another thread via Application.execute()? As the jME3 scene graph isn't thread safe, and modifying it outside the GL thread can cause issues.

I attach it using my timer class TimedInvocation, it's update is being alled in the simpleupdate()



package de.empirephoenix.util;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Vector;

public class TimedInvocation {
   public static Vector<Timedmethodinvocation> timedobjects = new Vector<Timedmethodinvocation>();
   
   public static void Update(){
      long curtime = System.currentTimeMillis();
      synchronized(timedobjects){
         Iterator<Timedmethodinvocation> iter = timedobjects.listIterator();
         while(iter.hasNext()){
            Timedmethodinvocation current = iter.next();
            current.Update(curtime);
            if(current.isFinished){iter.remove();}
         }
      }
   }
   
   public static void Add(Object toexecute,String methodname,int milisdelay){
      Add(toexecute, methodname, milisdelay,null,null);
   }
   
   public static void Add(Object toexecute,String methodname,int milisdelay,Object argument, Class objectclass){
      synchronized(timedobjects){
         try {
            timedobjects.add(new Timedmethodinvocation(toexecute,methodname,milisdelay,argument,objectclass));
         } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }
   }
   
}

class Timedmethodinvocation{
   public boolean isFinished = false;
   private final Object objecttouse;
   private final Method toinvoke;
   private final long timetoexecute;
   private final Object argument;
   
   Timedmethodinvocation(Object toexecute, String methodname, int milisdelay,Object argument,Class objectclass) throws SecurityException, NoSuchMethodException{
      objecttouse = toexecute;
      if(argument != null){
         toinvoke = toexecute.getClass().getMethod(methodname,objectclass);
      }else{
         toinvoke = toexecute.getClass().getMethod(methodname);
      }

      timetoexecute = milisdelay + System.currentTimeMillis();
      this.argument = argument;
   }
   
   void Update(long curtime){
      if(curtime >= timetoexecute){
         try {
            if(argument != null){
               toinvoke.invoke(objecttouse, argument);
            }else{
               toinvoke.invoke(objecttouse);
            }
         } catch (Exception e) {e.printStackTrace();}
         isFinished = true;
      }
   }
}



But as I said in the testapllication that works so either this is one really dumb mistake i made and I'm unable to see it, or there is some crazy stuff happenign in the synchronizations ^^

I am pretty sure I had a similar bug when the scene graph was played around with (any part of the scene graph) in a different thread than the GL thread.

Yes, oddly I get it also when i directly load the model at that place in the simplegameupdate, where it normally addsa  job to the background loader. So this is not the problem :confused: (Also I make sure that it is the same thread than the one that ran simpleappinit, made an check for this, so it is definitly in the opengl thread)

Its not just about loading or attaching, any method that modifies the scene graph in some way could create an issue. setLocalTranslation, even the methods in AnimControl.

Well i load the model in a second thread, but add it in the opengl one, and do not modify it outside opengl thread <anymore after that. oddly, when i disable loading materials, and the default red one is used, everything works.



in a testprogramm, however the loading with models in a second thread works perfectly reliable

I found it, it seems, that between creating the loadging thread, and initializing the manager and then loading the first model needs to be a minimum delay, when calling any other function first it works now reliable. (I thi I will add a sleep(10)) just to make sure, as 10 ms startup won't hurt really.

So wait you're creating the AssetManager in a loading thread and then using it there? Or are you using the AssetManager that comes with Application?

Using the one that comes with simpleapp,



This works:


mythread = Thread.currentThread();
      myself = this;
      manager.registerLocator("/de/empirephoenix/models/", "com.jme3.asset.plugins.ClasspathLocator","material","meshxml","jpg");
      
      LoaderThread loader = new LoaderThread(manager);
      loader.setDaemon(true);
      loader.start();
      
      this.setShowSettings(false);
      this.setPauseOnLostFocus(false);
      
      PointLight pl = new PointLight();
      pl.setPosition(new Vector3f(10, 10, -10));
      rootNode.addLight(pl);
      
      try{
         client = new Client(SettingsConfig.getVerifyer());
         client.addListener(new CObjectManager());
         client.addClassTable(new NewHorizonsClassTable());
         client.connect(new InetSocketAddress("localhost",1000));
      }catch(Exception e){
         System.out.println("Failture in connect");
         e.printStackTrace();
         
      }
      

      this.flyCam.setMoveSpeed(500f);
      this.cam.setFrustumFar(4000);



This not:


      mythread = Thread.currentThread();
      myself = this;
      manager.registerLocator("/de/empirephoenix/models/", "com.jme3.asset.plugins.ClasspathLocator","material","meshxml","jpg");

      this.setShowSettings(false);
      this.setPauseOnLostFocus(false);
      
      PointLight pl = new PointLight();
      pl.setPosition(new Vector3f(10, 10, -10));
      rootNode.addLight(pl);
      
      try{
         client = new Client(SettingsConfig.getVerifyer());
         client.addListener(new CObjectManager());
         client.addClassTable(new NewHorizonsClassTable());
         client.connect(new InetSocketAddress("localhost",1000));
      }catch(Exception e){
         System.out.println("Failture in connect");
         e.printStackTrace();
         
      }
      
      
      LoaderThread loader = new LoaderThread(manager);
      loader.setDaemon(true);
      loader.start();