Updating render error

I have a java class where I’ve made a thread with a SimpleApplication,



[java]new Thread(new Runnable(){

public void run(){

JME.setShowSettings(false);

AppSettings settings=new AppSettings(true);

settings.put(“Width”, 640);

settings.put(“Height”, 480);

settings.put(“Title”, “My Game”);

settings.put(“VSync”, true);

//settings.put(“Samples”, 4);

JME.setSettings(settings);



JME.start();

}

}).start();[/java]





this java class has to update the position of the spatials inside the SimpleApplication every second but when I try to call the method that updates the render:



[java]public void actualizaRender(){



rootNode.updateGeometricState();

rootNode.updateLogicalState(tpf);



renderManager.render(tpf);

}[/java]



I get the following error:



[java]Uncaught exception thrown in Thread[AWT-EventQueue-1,4,file:D:/Users/Roberto/Desktop/SID/PFC David/Traineras/build/classes/-threadGroup]

java.lang.NullPointerException

at org.lwjgl.opengl.GL11.glClearColor(GL11.java:569)

at com.jme3.renderer.lwjgl.LwjglRenderer.setBackgroundColor(LwjglRenderer.java:442)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:704)

at com.jme3.renderer.RenderManager.render(RenderManager.java:742)

at tridimensional.Prueba1.actualizaRender(Prueba1.java:252)

at tridimensional.Prueba1.refresco(Prueba1.java:838)

at SQL.SQLProcessor.viewObject(SQLProcessor.java:939)

at interfaz.TabViewObject.actionPerformed(TabViewObject.java:205)

at javax.swing.Timer.fireActionPerformed(Timer.java:271)

at javax.swing.Timer$DoPostEvent.run(Timer.java:201)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)[/java]



I have read that this is because I’m using threads, but I need to use them because the java class is in charge of obtaining the position of the spatials from a database and sending this information to the SimpleApplication in order to render the scene. Is there something I can do to fix that?



Thanks

I have fixed the problem using this:



[java]enqueue(new Callable() {

public Void call() throws Exception {

rootNode.updateGeometricState();

rootNode.updateLogicalState(tpf);



renderManager.render(tpf);

return null;

}

});[/java]

It seems your multithreading model is a bit messy, maybe you want to have a look at this:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:multithreading