Scene graph is not properly updated for rendering. State was changed after rootNode.updateGeometricState() call

Hello,

In fact, I’m not familiar with JMonkey Engine, our teacher give us the basic code for draw an earth. But I don’t have enough time to learn all the basic principles of JMonkey Engine.

I need to add the code to show all the airports across the world.

I create a new class Earth (extends SimpleApplication), and I add a method displayPlace(float lattitude, float longitude) to display all the airports around the world. But the scene breaks down quickly and throws the exception java.lang.IllegalStateException.

here is the method displayPlace(float lattitude, float longitude) :

public void displayPlace(float latitude, float longtitude) {
	Sphere sphere = new Sphere(16,8,0.005f);
	Geometry palce = new Geometry("Aiport",sphere);
	Vector3f position = new Vector3f();
	position = geoCoordTo3dCoord(latitude,longtitude);
	Material mat1 = new Material (assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
	mat1.setColor ("Color",ColorRGBA.Red);
	place.setMaterial(mat1);
	place.setLocalTranslation(position);
	rootNode.attachChild(place);
}

the method geoCoordTo3dCoord(float, float) is used to convert the coordinate of latitude and longitude to coodinate on the earth.

In another class windows I created the basic interfaces for the application. I added a JButton to listen to the click on the Button showAllAirportButton, the whole code as follows:

showAllAirportButton.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			ArrayList<Airport> listAirport = Airport.getListAirport();
			Iterator<Airport> it = listAirport.iterator();
			while(it.hasNext()){
				Airport airport = it.next();
				float lat = (float)airport.getLatitude();
				float lon = (float)airport.getLongitude();
				canvasApplication.displayPlace(lat, lon);
			}
		}
	});

So, the principle is simple, but I cannot get the right result. I don’t know if it’s because of the method simpleUpdate(float tpf) , in fact, I don’t know where I should add this method to my code.

I’m really strange about the JMonkey Engine, but project has to be handed in immediately, so please help me. Thanks.

Hi,

Modification of the scene should be done in the jme render thread. And you call it into a Swing Thread.
Embedded the code of actionPerformed into a SimpleApplication.enqueue (see it javadoc).

public void actionPerformed(ActionEvent e) {
  canvasApplication.enqueue(new Callable<Void>(){
   ....
  });
}

Thanks, I solved it.