Objects randomly not rendering on OffScreen Canvas
Posted by
tinker on
Aug 27, 2017; 9:29am
URL: https://forum.jogamp.org/Objects-randomly-not-rendering-on-OffScreen-Canvas-tp4038163.html
I'm writing an application that uses Java3D to do rendering of snapshot stills of its state, in other words doesn't have a live a object graph that renders on the screen.
For every snapshot requested the application builds up a new Canvas, new SimpleUniverse and creates a new object graph and triggers a render. So far, so good. But randomly some or all objects do not render in what appears to be some sort of race condition. A scene that renders perfectly once may be completely empty when re-rendered later, although the scene contents and input is exactly the same.
The background, which is a solid color, always appears to render, though. The problem seems to occur more often when there is a larger number of objects in the graph.
Any advice or tips or theories on how to deal with this would be greatly appreciated.
This is the implementation of my OffScreenCanvas:
public class OffScreenCanvas3D extends Canvas3D {
public OffScreenCanvas3D(GraphicsConfiguration config) {
super(config, true);
}
BufferedImage doRender(int width, int height) {
BufferedImage bImage = new BufferedImage(width,
height,
BufferedImage.TYPE_INT_ARGB);
ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA,
bImage);
setOffScreenBuffer(buffer);
Screen3D virtualScreen = getScreen3D();
virtualScreen.setSize(new Dimension(width, height));
virtualScreen.setPhysicalScreenWidth(0.0254/90.0 * width);
virtualScreen.setPhysicalScreenHeight(0.0254/90.0 * height);
renderOffScreenBuffer();
waitForOffScreenRendering();
return getOffScreenBuffer().getImage();
}
}
Basically, the object graph is built and then the doRender method is called to return a BufferedImage.