Skip to main content

adding JCanvas3D component to JFrame doesn't work

3 replies [Last post]
blueradiobutton
Offline
Joined: 2006-10-18

Hi,

I am experiencing problems with JCanvas3D,too. I created a SimpleUniverse ( that contains a rotating ColorCube ) that renders into the offscreen Canvas3D of a JCanvas3D object. The JCanvas3D crashes and I don't have any clue why.

I followed the threads

- http://forums.java.net/jive/thread.jspa?forumID=70&threadID=20212&messag...
- http://forums.java.net/jive/thread.jspa?forumID=70&threadID=20619&messag...

and have seen the issue

https://java3d.dev.java.net/issues/show_bug.cgi?id=397

and tried to follow the instructions given there. The code snippets and errors follow in replies to this topic.

Cheers,
Florian

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
blueradiobutton
Offline
Joined: 2006-10-18

When I put the line that creates the SimpleUniverse after the line that adds the canvas to my frame, the following exception is thrown:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Canvas3D: Illegal operation in off-screen mode
at javax.media.j3d.Canvas3D.stopRenderer(Canvas3D.java:1670)
at com.sun.j3d.exp.swing.JCanvas3D.createOffScreenBuffer(JCanvas3D.java:342)
at com.sun.j3d.exp.swing.JCanvas3D.createCanvas(JCanvas3D.java:321)
at com.sun.j3d.exp.swing.JCanvas3D.getOffscreenCanvas3D(JCanvas3D.java:361)
at org.globalse.sysiphus.rat.plugins.browse3D.BrowserView.initUI(BrowserView.java:60)
at org.globalse.sysiphus.rat.plugins.browse3D.BrowserView.(BrowserView.java:32)
at org.globalse.sysiphus.rat.plugins.browse3D.Browse3DPlugin$Browse3DAction.actionPerformed(Browse3DPlugin.java:91)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:334)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5554)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5319)
at java.awt.Container.processEvent(Container.java:2010)
at java.awt.Component.dispatchEventImpl(Component.java:4021)
at java.awt.Container.dispatchEventImpl(Container.java:2068)
at java.awt.Component.dispatchEvent(Component.java:3869)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
at java.awt.Container.dispatchEventImpl(Container.java:2054)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3869)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

blueradiobutton
Offline
Joined: 2006-10-18

private void initUI() {

GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice();

JCanvas3D canvas = new JCanvas3D(device);

setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1024, 1024);

// setup and add canvas to main frame

canvas.setLocation(64, 64); // added since layout is null
canvas.setSize(512, 512); // added since layout is null
canvas.setBackground(Color.BLACK); // for test purposes

SimpleUniverse universe = new SimpleUniverse(canvas
.getOffscreenCanvas3D());

add(canvas);
BranchGroup sceneGraph = createSceneGraph();
sceneGraph.compile();
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(sceneGraph);

// make JFrame visible
setVisible(true);

}

private BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
Transform3D rotate = new Transform3D();
rotate.rotX(Math.PI / 4.0d);
TransformGroup objRotate = new TransformGroup(rotate);
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

objRotate.addChild(new ColorCube(0.4));
objSpin.addChild(objRotate);
Alpha rotationAlpha = new Alpha(-1, 4000);
RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
objSpin);
BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
objRoot.addChild(objSpin);
return objRoot;
}

blueradiobutton
Offline
Joined: 2006-10-18

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Canvas3D: Illegal operation in off-screen mode
at javax.media.j3d.Canvas3D.stopRenderer(Canvas3D.java:1670)
at com.sun.j3d.exp.swing.JCanvas3D.createOffScreenBuffer(JCanvas3D.java:342)
at com.sun.j3d.exp.swing.JCanvas3D.createCanvas(JCanvas3D.java:321)
at com.sun.j3d.exp.swing.JCanvas3D.ancestorAdded(JCanvas3D.java:254)
at javax.swing.AncestorNotifier.fireAncestorAdded(AncestorNotifier.java:68)
at javax.swing.AncestorNotifier.componentShown(AncestorNotifier.java:175)
at java.awt.Component.processComponentEvent(Component.java:5386)
at java.awt.Component.processEvent(Component.java:5334)
at java.awt.Container.processEvent(Container.java:2010)
at java.awt.Window.processEvent(Window.java:1161)
at java.awt.Component.dispatchEventImpl(Component.java:4021)
at java.awt.Container.dispatchEventImpl(Container.java:2068)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3869)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
CANVAS CRASHED!!!