JME with Swing GUI: java.lang.IllegalStateException: Scene graph is not properly updated for renderi

Hi everyone!



I built a very simple GUI for a “game” in JME. I just want to choose a model, turn it, give it a name. (It’s supposed to be some kind of character creation like in MMORPGs.) The Problem is, I get an exception a lot. It’s very weird, because sometimes it happens at the first click, sometimes it happens after lots of clicks and sometimes… after a medium amount of clicks. :wink: Does anybody know why this is happening and how to solve it?



The exception im getting (when I’m getting it while changing the name its “Gui Node”, else it’s “Root Node”):



Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.IllegalStateException: Scene graph is not properly updated for rendering.

Make sure scene graph state was not changed after

rootNode.updateGeometricState() call.

Problem spatial name: Gui Node

at com.jme3.scene.Spatial.checkCulling(Spatial.java:223)

at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:439)

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

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

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:217)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:226)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

at java.lang.Thread.run(Unknown Source)





My code (not all of it, but the most important):



[java]

final JTextField nameField = new JTextField("");

nameField.setBounds(860, 10, 140, 20);

nameField.addActionListener(new ActionListener() {



@Override

public void actionPerformed(ActionEvent e) {

BitmapText name = (BitmapText) canvasApplication.getGuiNode().getChild(0);

name.setText(nameField.getText());

float lineWidth = 0f;

if (name != null) lineWidth = name.getLineWidth();

name.setLocalTranslation(400-(lineWidth/2), 600, 0);

}

});

panel.add(nameField);

[/java]

You cannot modify the scene graph outside the rendering thread.

You’re doing many kinds of modifications in actionPerformed, which runs in the EDT, this is not allowed.

Use the Callable class and submit operations to be executed on the rendering thread using Application.enqueue() method.

1 Like

Wow! Thank you so much! With the enqueue() method it didn’t crash at all! Great! :slight_smile: