3. recreate canvas (like in SwingGui example in jmetest/utils/)
//
GL STUFF
// make the canvas:
canvas = DisplaySystem.getDisplaySystem("lwjgl").createCanvas(width, height);
// add a listener... if window is resized, we can do something about it.
this.keyEvents=new ComponentAdapter() {
public void componentResized(ComponentEvent ce) {
doResize();
}
};
canvas.addComponentListener(this.keyEvents);
// Mauseingaben an den 3D Frame routen.
KeyInput.setProvider( KeyInput.INPUT_AWT );
AWTMouseInput.setup( canvas, false );
// Hier wird die 3D Szene initalisiert.
impl = new CanvasJME(width, height,this);
JMECanvas jmeCanvas = ( (JMECanvas) canvas );
jmeCanvas.setImplementor(impl);
jmeCanvas.setUpdateInput( true );
//
END OF GL STUFF
i get an error when doing step 2:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:315)
at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:339)
at sun.awt.RepaintArea.updateComponent(RepaintArea.java:239)
at sun.awt.X11.XRepaintArea.updateComponent(XRepaintArea.java:43)
at sun.awt.RepaintArea.paint(RepaintArea.java:216)
at sun.awt.X11.XComponentPeer.handleEvent(XComponentPeer.java:683)
at java.awt.Component.dispatchEventImpl(Component.java:4489)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
seems like the event handler of the swing gui has a problem when i remove the canvas.I was not able to figure out how to clean the eventQueue.
By ignoring this problem this seems to be a good way to me. Am i a noob, or is this a way to go ?
or by avoiding the repaint call on the canvas (done in a separate thread in 1.0
Thanks for that suggestion, When i suspend the thread of repainting the problem is done !
That leads me to another question: The example in jmetest/utils/JMESwingTest run the thread on and on, so one cpu core is under full load.
Isn't it a better solution to call canvas.repaint on the end of the render method ? Or to suspend the thread after repaint instead of yield, and make a wakeup in the render method ?
I wonder if it should be that the painting thread completly uses one cpu core (load 1.0) just for its job to repaint . . .
Is there a reason not to suspend and wakeup the thread per Frame ?
I don't believe you will run into any big problem by ignoring the queued up paint's NPE. You may be able to eliminate it by cleaning up the canvas inside the paint thread in some special order or by avoiding the repaint call on the canvas (done in a separate thread in 1.0, or inside the super class in 2.0)
2.0 actually has no thread… it just calls repaint after paintGL is done. As for stopping/suspending the thread, I'd suggest using a flag instead that you can set to allow the thread to naturally finish (or to skip painting)