Monday, June 16, 2014

Java 3D problem - No X11 DISPLAY variable was set

I have following exception during Java3D application startup:

No X11 DISPLAY variable was set, but this program performed an operation which requires it.
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
       at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:77)

Problem is quite easy understand and resolve. Java 3D drive don't know address of X11 windows server. X11 server address should be stored in environment variable "DISPLAY". Environment could be set up like this:

export DISPLAY=:0.0

This will work just in case that your X11 server is at localhost. How to find X11 server address is nicely described at http://stackoverflow.com/questions/784404/how-can-i-specify-a-display

Monday, June 9, 2014

Java 3D exception: TransformGroupRetained : Can't find hashKey

Following exception appears in my Java 3D application:

TransformGroupRetained : Can't find hashKey
Exception in thread "J3D-TransformStructureUpdateThread-1" java.lang.ArrayIndexOutOfBoundsException: -1
 at javax.media.j3d.TransformGroupRetained.updateChildLocalToVworld(TransformGroupRetained.java:979)
 at javax.media.j3d.TransformGroupRetained.updateChildLocalToVworld(TransformGroupRetained.java:961)
 at javax.media.j3d.TransformGroupRetained.processChildLocalToVworld(TransformGroupRetained.java:825)
 at javax.media.j3d.TransformStructure.processCurrentLocalToVworld(TransformStructure.java:306)
 at javax.media.j3d.TransformStructure.processMessages(TransformStructure.java:186)
 at javax.media.j3d.StructureUpdateThread.doWork(StructureUpdateThread.java:83)
 at javax.media.j3d.J3dThread.run(J3dThread.java:250)

In my case I incorrectly used one of available ways to hide and show part of 3D objects graph. I use javax.media.j3d.Link and when I wand to show specific subgraph I call:

link.setSharedGroup(mySharedGroup);

and similary I called when I want to hide some object I called:

link.setSharedGroup(null);

I works fine up to the moment when setSharedGroup was called with same object parameter more than once. It leads to "TransformGroupRetained : Can't find hashKey" Exception. Fix is quite simple:

if(link.getSharedGroup() == null){
    link.setSharedGroup(mySharedGroup);
}

and

if(link.getSharedGroup() != null){
    link.setSharedGroup(null);
}

This should help. Hopefully it will save you some time.

regards

Monday, June 2, 2014

Java 3D problem - java.lang.UnsatisfiedLinkError: Can't load library: /System/Library/Frameworks/gluegen-rt.Framework/gluegen-rt

Correctly set Java 3D in eclipse project could be tricky. I'll try to write down problems that I have met.

Compilation problem

Double check that there are latest (1.6.*) version of Java 3D at class path.

Caused by: java.lang.UnsatisfiedLinkError: Can't load library:

Following exception:
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: /System/Library/Frameworks/gluegen-rt.Framework/gluegen-rt
Means that is class path is not 'gluegen-rt'. Check it in eclipse project setting.