Posted by
philjord on
Feb 05, 2016; 11:33pm
URL: https://forum.jogamp.org/Canvas3D-disappears-when-resizing-JComponets-on-Windows10-tp4036118p4036124.html
Tom,
I can't tell you the exact cause but I can tell you how to work around the issue.
It appears to have been around since 2002
https://www.mail-archive.com/java3d-interest@java.sun.com/msg18026.htmlThe issue is that the renderer decides not to update the Canvas3D in the name of efficiency. However something else comes in and clears the Canvas3D to grey in a race condition with the Renderer, so you get the crazy sometimes grey output.
The work around is to always have at least 1 non passive behavior in the scene graph
Like this:
import java.awt.Frame;
import java.util.Enumeration;
import javax.media.j3d.Behavior;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.WakeupCondition;
import javax.media.j3d.WakeupOnElapsedFrames;
import javax.swing.SwingUtilities;
import javax.vecmath.Point3d;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Java3DSimpleTest
{
public static void createAndShowGUI()
{
BranchGroup root = new BranchGroup();
root.addChild(new ColorCube(0.5f));
root.addChild(go);
Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration()) {
public void postSwap()
{
System.out.println("swap called");
}
};
SimpleUniverse universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(root);
Frame frame = new Frame("Java3DSimpleTest");
frame.add(canvas);
frame.setSize(400, 400);
frame.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
createAndShowGUI();
}
});
}
private static GoBehavior go = new GoBehavior();
private static class GoBehavior extends Behavior
{
private WakeupCondition FPSCriterion = new WakeupOnElapsedFrames(0, false);
public GoBehavior()
{
setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.POSITIVE_INFINITY));
setEnable(true);
}
public void initialize()
{
wakeupOn(FPSCriterion);
}
@SuppressWarnings("rawtypes")
public void processStimulus(Enumeration criteria)
{
wakeupOn(FPSCriterion);
}
}
}
Notice if you comment out the line
root.addChild(go);
then the console no longer fills with swap called.
Sorry I don't don't the actual cause and a decent way around whatever is painting the grey.
Phil.