[SOLVED] Problem with off screen rendering

Hi, I get this error…

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

It is odd because I am attaching the scene spatial to the off screen viewport root via the rendering thread. The scene spatial works fine if I attach it to the root node of the simple application.

The off screen viewport (preView) seems to instantiate fine with Texture2Ds.

Is there something I need to do in addition when using off screen viewport instead of the simple application root, such as calling updateGeometricState?

Thanks
Penny

ps I am creating a root node and adding to the off screen viewport using…

attachScene(root);

this works fine without error.

As soon as I try to root.attachChild(node) with in the rendering thread I get the error.

I am very confident that all changes are made with in the rendering thread as it all works fine when the scene is attached to the SimpleApplication.rootNode

The thing you’re attaching to the offscreen, are you doing

thing.updateGeometricState();

and

thing.updateLogicalState(tfp);

in simpleUpdate() method ?

EDIT: Just read about the render thread, so in there after you attach it instead ?

Normally, SimpleApplication performs the updateLogicalState() and updateGeometricState() calls on the root node. If you have your own root node, you need to be the one responsible for making those two calls against it.

ok brill!! The following worked a treat…

public void simpleUpdate(float _tpf)
 {
 offScreenRoot.updateGeometricState();
 }

I will add…

updateLogicalState()

as Momofo_Fan suggests. Which should go first?

I am going to write my own little api to handle off screen rendering as I will require 0,1 or many instances.

Thanks
Penny

Manage your off screen viewport with an app state. Do updateLogicalState in update() and do updateGeometricState() in render.

ok, that makes sense.

To confirm, the AppState could update the roots of several viewports in the way you suggested? and would perform the updates at the correct moments?

Thanks

If you o updateLogicalState in update() and do updateGeometricState() in render.

Thanks Everyone for your help. :smile:

Hi,

I am on to the next stage. I have popped a picture on to my gui using the texture of the off screen buffer but the camera doesn’t seem to be able to focus the scene. The following image is of my gui that has a background colour of yellow with a 50x50 picture textured with the frame buffer output colour texture.

There should be sky, sun, mountains and water etc.

I am sure it is something simple that I am unaware of so your help will be most grateful.

My project runs without errors and below is some excerpts of what I believe to be the crucial code.

private static class ProjectionState extends AbstractAppState
 {
 public void update(float _timePerFrame)
  {
  for(Cosm c:cosmsActive)
   {
   c.updateLogicalState(_timePerFrame);
   }
  }
 public void render(RenderManager _renderManager)
  {
  for(Cosm c:cosmsActive)
   {
   c.updateGeometricState();
   }
  for(Projection p:projectionsActive)
   {
   if(p.voint!=null)
    {
    p.camera.setLocation(p.voint.getWorldTranslation());
    p.camera.setRotation(p.voint.getWorldRotation());
    }
   }



camera=new Camera(Math.round(w),Math.round(h));
camera.setFrustumPerspective(45f,w/h,0.05f,10000f);


int tw=Math.round(w);
int th=Math.round(h);
colorTexture=new Texture2D(tw,th,Image.Format.ABGR8);
depthTexture=new Texture2D(tw,th,Image.Format.Depth32F);
frameBuffer=new FrameBuffer(tw,th,1);
frameBuffer.setColorTexture(colorTexture);
frameBuffer.setDepthTexture(depthTexture);



 viewPort=renderManager.createPreView("Projection",camera);
 viewPort.setOutputFrameBuffer(frameBuffer);

  viewPort.addProcessor(c.fpp);
  viewPort.attachScene(c.root);

Hard to say without knowing a whole bunch more…

like camera position relative to thing you’re looking at…
values of w and h…
…cod that sets up to render the quad.

I don’t know what the picture is supposed to look like but it could just be that you are really zoomed in?

Edit: have you looked the TestRenderToTexture example?

the scene size is 100x100 and the camera is in the middle about 20m above. When the exact same scene is rendered to the main buffer is renders fine.

the size of the textures is 900x650 - thats the size I decided that would be the default size, designed for when running from a website page.

The scene is pretty much one of the test examples showing water, with sky, mountains and sun. Works fine when rendered to the main view.

The settings for the camera are exactly how I set it for the main view. I am not sure how it is zoomed in on this projection or differs from the main view.

The pictures added to the default gui using pretty much the standard objects…

pictures[pi]=new Picture((Texture2D)p.getColorTexture(),false);
pictures[pi].setBounds(200,400,50,50);
gui.addToTop(pictures[pi]);

When I pan the camera around and move, the texture flickers and sometimes goes blue.

I believe the scene is being rendered otherwise it would be blank.

I believe the texture is being displayed correctly as I have displayed many textures correctly in the exact same manner.

The only thing new is my off screen buffering.

It seems the camera is out of focus as you say, but what it causing this is a mystery.

Ok, I have removed the scene to only show the background colour…

I have seen this type of artefact when I didnt map my textures correctly.
I am sure the picture is displaying the texture correctly. The depth texture does not display this issue so I am happy that the issue it is not in the displaying for the textures.

I thought it might be the camera viewport not being set so I have added…

camera.setViewPort(0,0,w,h);

but it had no affect.

I have eliminated camera position and scene from the issue.

Help much appreciated. Thanks.

I have found the issue.

It is in my own code.

It is do to with scaling.

I implemented an extension of Picture which has convenience routines to display images which work fine but since I have been investigating off screen rendering I have recently been passing the textures instead of images and my code wasnt handling the sizes and scale correctly. Hence the result which I was familiar with as before.

Sorry to waste your time but it was very helpful to me and I found the cause of the issue :smile:

Many Thanks

Sorted. Thanks.

1 Like