Add/remove jME Canvas results in a deadlock

I have a Swing app with a jME Canvas (precisely a LwjglCanvas) in it. But it is not in the main window all the time. I have to add and remove it as needed, when my app change state. Then I need to start and stop jME. I have a simple class that extends Application, then the obvious thing I do is to call Application.stop() method when I have to stop jME, which in turn calls LwjglCanvas.destroy(). I actually blocks in the call to Canvas.removeNotify() which is performed in the EDT. It locks in the line synchronized (reinitReqLock). Also, after I call stop and call removeAll in the parent component a “shadow” of the canvas continues over my window, that’s messy.

Perhaps I’m doing it wrong but it seems there’s a concurrency problem there, because the events are not always the same, not deterministic. HELP :open_mouth: !!


I added a new feature to TestCanvas that shows how to add/remove the canvas dynamically. Its available in the latest SVN.

Hey thanks :).

Your code doesn’t work here. I had to add this:


context = (JmeCanvasContext) app.getContext();

context.setSystemListener(app); // <<

canvas = context.getCanvas();
canvas.setSize(settings.getWidth(), settings.getHeight());

Ok it works but I want to actually dispose the canvas and release all jME resources. This is where the problem actually is I think.