LwjglCanvas randomly detaching from SWT component

Hello all,



I am embeding a JME3 application into an SWT component (via the SWT_AWT bridge) with the following code. This launches fine, but after building and rebuilding the scene graph for a few seconds, the application closes and the LwjglCanvas detaches from the AWT frame, leaving the default grey java.awt.Component background in its place.



[java] // Place JME3 canvas on the parent composite



Composite geometryComposite = new Composite(

parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);



geometryApplication = new GeometryApplication(); // GeometryApplication is a subclass of com.jme3.app.SimpleApplication

geometryApplication.setSettings(settings);

geometryApplication.setPauseOnLostFocus(false);

geometryApplication.createCanvas();



JmeCanvasContext canvasContext =

(JmeCanvasContext) geometryApplication.getContext();

canvasContext.setSystemListener(geometryApplication);



Frame window = SWT_AWT.new_Frame(geometryComposite);

Canvas canvas = canvasContext.getCanvas();

window.add(canvas);



window.pack();

window.setVisible(true);



// Start the canvas



EventQueue.invokeLater(new Runnable() {



@Override

public void run() {

geometryApplication.startCanvas();

}

});

[/java]



Here are the last few lines of output to the console before the canvas detaches.



Jul 27, 2012 12:25:36 PM com.jme3.system.lwjgl.LwjglCanvas$GLCanvas removeNotify

INFO: EDT: Application is stopped. Not restoring canvas.



What are some possible causes for a canvas detaching like this? Could this have anything to do with the scene graph updating too often?



Thanks,

– Andrew Belt

You are telling the application to close, thus it closes. You’re calling Application.stop() somewhere basically.

I found out that I was modifying the scene graph from another thread somewhere, causing the canvas to panic. I moved it to the main thread, and I have no problems now!