Exception with second viewport/camera

Hello, I was attempting to create a second camera/viewport for seperating out objects for postProcessor type effects.

here is my test code:

package test;

import com.jme3.app.SimpleApplication;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;

public class TestViewport extends SimpleApplication {

public static void main(String[] args) {
TestViewport t = new TestViewport();

ViewPort secondViewport;
Camera secondCamera;
Node rootNode2;

public void simpleInitApp() {
secondCamera = this.cam.clone();
secondViewport = this.renderManager.createMainView(“secondViewPort”, secondCamera);
rootNode2 = new Node(“rootNode2”);

public void update() {
super.update(); //To change body of generated methods, choose Tools | Templates.
} [/java]

I get the exception:

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: rootNode2

which makes no sense to me since I am doing no multi-threading of any kind.

Thanks for any help.


Actually this error message hints you toward multi threading problem because it’s the most common cause of this issue.
In your case however it a lot simpler. The rootNode2 you created is never updated. The built in root node is automatically updated, but not the one you create.
So you have to call in your simpleUpdate
And ignore the warning that it throws at you.

1 Like

Thanks for the quick response nehon!

That fixed the exception but now I cannot see those objects attached to the new viewport.

If I attach them to rootNode I can see them but not in rootNode2…

Do I need to call viewport2.render() or some other method? Also does it matter if you create a new camera or just attach a second viewport to the built in camera?

No it should be rendered automatically, but many things can happen. Could you please post the complete code.
You should make the second viewport to not clear color and depth. That’s probably not your issue, but you’ll have it at some point.



Hehe, I attached some “overlay” type objects to a node but forgot to attach it to the rootNode2 above.

Thanks again for the help, Nehon.

I am enjoying JME quite a bit so far.

1 Like