Outliner Filter Crashing The Application

Hello,
I’m using a nice library from the JME store for outlining some of my entities:

The problem is that it crashes my application when I detach the outlined Spatial from the root node (threading issue - see below stack trace).

Here is the code which attaches the outline filter to the Spatial:

	private void showOutlineFilterEffect(Spatial model, int width, ColorRGBA color) {
		Filter outlineFilter = model.getUserData("OutlineFilter");
		OutlinePreFilter outlinePreFilter;
		if (outlineFilter == null) {
			ViewPort outlineViewport = renderManager.createPreView("outlineViewport", cam);
			FilterPostProcessor outlinefpp = new FilterPostProcessor(assetManager);
			outlinePreFilter = new OutlinePreFilter();
			outlinefpp.addFilter(outlinePreFilter);
			outlineViewport.attachScene(model);
			outlineViewport.addProcessor(outlinefpp);
                        //
                         outlineFilter = new OutlineFilter(outlinePreFilter);
                        ((OutlineFilter)outlineFilter).setOutlineColor(color);
                        ((OutlineFilter)outlineFilter).setOutlineWidth(width);
                         model.setUserData("OutlineFilter", outlineFilter);
			
			fpp.addFilter(outlineFilter);
		} else {
			outlineFilter.setEnabled(true);
			  //
                         ((OutlineFilter)outlineFilter).getOutlinePreFilter().setEnabled(true);
                         
		}
	}

And here is the exception’s stack trace which happens when I detach the Spatial:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,6,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: s@1
	at com.jme3.scene.Spatial.checkCulling(Spatial.java:361)
	at com.jme3.scene.Geometry.checkCulling(Geometry.java:149)
	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:717)
	at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:710)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1096)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1150)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:272)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:153)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:234)
	at java.lang.Thread.run(Thread.java:745)

I guess I need to somehow disable the filter before I detach the Spatial…
What do you think?

Adi

1 Like

You showed the code attaching it, but your problem lies in detaching it. Either way, you should interact with JME in the JME thread. Use app.enqueue if necessary.

2 Likes

As Jay indicates, this line of the error says it all. It’s not optional. It’s not just a warning advisory.

You absolutely cannot under any circumstances (no, not even that one) modify the scene graph from another thread.

2 Likes

I’m aware of the constraint of not modifying the scene graph from another thread and I didn’t do that, at least not explicitly. It was something in my usage with the outline library that caused the violation.
Anyway I have managed to avoid the problem by detaching my Spatial from the Outliner’s view port (it creates a view port when you outline your Spatial) just before detaching my Spatial from it’s parent.
I don’t really understand why it solved the problem but now it works fine.

If you manage your own viewport then you also need to manage the updateLogicalState() and updateGeometricState() calls or you will get the same error.

If an object was part of the rootNode scene then it was already getting these calls automatically. When you detach it from that scene then now it’s “unmanaged” as far as the viewport is concerned… and thus you’d need to call updateLogicalState() and updateGeometricState() yourself.

1 Like