Scene graph is not properly updated for rendering

Hi,

When i run my application it runs for around 5 seconds then provides me with this error :

Feb 01, 2013 2:10:42 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: Root Node
at com.jme3.scene.Spatial.checkCulling(Spatial.java:260)
at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:647)
at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:640)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:974)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Unknown Source)

it has something to do with this part of my code?
what its doing is reading a text file and getting the numbers from it ,
then changes the players x value according to the file , i added Thread.sleep(1000); because i dont want it to go so fast, im not sure if this is the best idea and thats whats stuffing it up. what would be another way for something to wait?
[java]
try {

		Scanner scanner = new Scanner(file);
		while (scanner.hasNextLine()) {
			String line = scanner.nextLine();
			Scanner lineScanner = new Scanner(line);
			lineScanner.useDelimiter(" ");

			while (lineScanner.hasNext()) {
				String part = lineScanner.next();

				if (part.contains("X")) {
					if (part.startsWith("X")) {
						String newX = part.replace("X", "");
						double valueX = Double.parseDouble(newX);
						Thread.sleep(1000);
						System.out.print("found X " + valueX + "\n");
						float myfloat = (float) (valueX);
						player.setLocalTranslation(myfloat, 0, 0);
					}

				}
				// System.out.println();
			}
		}

[/java]
thanks for any help:)

See the error message:

@kolijhaha said: Make sure you do not modify the scene from another thread!
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:multithreading
1 Like
@normen said: See the error message:

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

wow! fast reply, so if i use multi threading it should fix this issue?

@kolijhaha said: wow! fast reply, so if i use multi threading it should fix this issue?
Did you read the link? You probably call this code you posted from a swing button or so, the problem is you already have another thread, not that you need another one. Making swing guis for a game is harder, even if you have a GUI editor ;)
1 Like
@normen said: Did you read the link? You probably call this code you posted from a swing button or so, the problem is you already have another thread, not that you need another one. Making swing guis for a game is harder, even if you have a GUI editor ;)

thats all of the code no swing

[java]
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.Timer;

/**

  • Sample 4 - how to trigger repeating actions from the main update loop. In

  • this example, we make the player character rotate.
    */
    public class test extends SimpleApplication {
    protected static Geometry player;

    public static void main(String args) throws InterruptedException {
    test app = new test();
    app.start();
    aaa();
    }

    @Override
    public void simpleInitApp() {

     Box b = new Box(Vector3f.ZERO, 1, 1, 1);
     player = new Geometry("blue cube", b);
     Material mat = new Material(assetManager,
     		"Common/MatDefs/Misc/Unshaded.j3md");
     mat.setColor("Color", ColorRGBA.Blue);
     player.setMaterial(mat);
     rootNode.attachChild(player);
    

    }

    public static void aaa() {

     File file = new File(
     		"C:hello.txt");
    
     try {
    
     	Scanner scanner = new Scanner(file);
     	while (scanner.hasNextLine()) {
     		String line = scanner.nextLine();
     		Scanner lineScanner = new Scanner(line);
     		lineScanner.useDelimiter(" ");
    
     		while (lineScanner.hasNext()) {
     			String part = lineScanner.next();
    
     			if (part.contains("X")) {
     				if (part.startsWith("X")) {
     					String newX = part.replace("X", "");
     					double valueX = Double.parseDouble(newX);
     					Thread.sleep(1000);//this lol daniel
     					System.out.print("found X " + valueX + "\n");
     					float myfloat = (float) (valueX);
     					player.setLocalTranslation(myfloat, 0, 0);
     				}
    
     			}
     			// System.out.println();
     		}
     	}
     } catch (Exception e) {
     	System.out.println("What!");
     	e.printStackTrace();
     }
    

    }

}
[/java]

But you call it in the main method, so its not running on the update loop thread but on the main app thread, which finishes after app.start(). App.start() starts the actual application thread, to do things when the jme application starts use simpleInitApp:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_simpleapplication

@normen said: But you call it in the main method, so its not running on the update loop thread but on the main app thread, which finishes after app.start(). App.start() starts the actual application thread, to do things when the jme application starts use simpleInitApp: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_simpleapplication

ok i called it from simpleinitapp but now the screen goes blank and goes not responding

You have lots of Thread.sleep() there… They block the update loop.

@normen said: You have lots of Thread.sleep() there.. They block the update loop.

ohhhh so how can you sleep if it blocks updating? im guessing multithreading?:stuck_out_tongue:

@kolijhaha said: ohhhh so how can you sleep if it blocks updating? im guessing multithreading?:P
You can simply not block the update loop and do whatever you want to do after a certain time: [java] float time = 0; float maxTime = 1000; public void simpleUpdate(float tpf){ time += tpf; //this means "time = time + tpf;" and simply accumulates the current time per frame if(time>maxTime){ doStuff(); //do things, this will be called in 1s intervals time = 0; //reset counter } } [/java]

Please go though the jme tutorials first, you seem to be not very experienced in programming and game programming especially, the tutorials teach you a lot more than their headlines might suggest. Also, the question about multithreading was answered in the link I first posted…

ok thanks for the help

You need to break your while (line 53), so that each update loop runs only one or a few lines.
Then graphical update will occur any time you stop computing…

For example, you could move your lines 54 and next to @Normen’s ‘doStuff()’.