Java 3D in headless mode
Posted by Avi Kalcheim on Aug 17, 2017; 12:30pm
URL: https://forum.jogamp.org/Java-3D-in-headless-mode-tp4038145.html
I have a java3D application I am trying to execute in "batch" mode on a Linux machine without graphical environment.
It reads a macro file, do some work, then save graphics objects created with java3D.
I saw on gitHub you added recently a commit:
j3dcore: allow Java3D to operate in headless mode when using the noop… …
hharrison committed on Oct 29, 2016
// Java 3D cannot run in headless mode unless using the noop renderer
+ if (java.awt.GraphicsEnvironment.isHeadless() && pipelineType != Pipeline.Type.NOOP) {
+ throw new java.awt.HeadlessException();
+ }
+
So, on the java line I wrote:
java -Dj3d.rend=noop -Djava.awt.headless=true ….
Then, in the program if wrote:
GraphicsConfiguration preferredConfiguration;
boolean offScreenFlag;
Canvas3D canvas;
String headless = System.getProperty("java.awt.headless");
if (headless.equals("true"))
{
offScreenFlag = true;
preferredConfiguration = null; /// This is obviously wrong…
}
else
{
// Retrieve preferred graphics configuration.
preferredConfiguration = SimpleUniverse.getPreferredConfiguration();
if (preferredConfiguration == null)
{
// Write an error message to the logger and exit
….
}
offScreenFlag = false;
}
// Create canvas.
canvas = new Canvas3D(preferredConfiguration, offScreenFlag);
}
I am getting
Exception in thread "main" java.lang.NullPointerException: Canvas3D: null GraphicsConfiguration
at javax.media.j3d.Canvas3D.checkForValidGraphicsConfig(Canvas3D.java:943)
I presume I must supply a valid preferredConfiguration for the headless mode in some way, but I don’t know how.
Can you please help me ?