Reloading the canvas

Hello!

I have a Swing GUI with a inner class that extends JMECanvasImplementor, based on the setup in RenParticleEditor. I have a button that I want to reload everything, just as if the application had just been opened. I've been searching the forum, and it seems that other people have had similar problems, but I can't find any kind of definitive answer. I'd have thought it would be simple; just set the canvas to be a new instance of the class that extends the canvas implementer. But that doesn't work. Can anyone shed any light on how I should go about this?

Ah, okay. I thought it would be simpler that way. Well I'm trying to clear everything inside my class that extends JMECanvasImplementor (called Scene), and then run the doSetup() method that I'm overriding, which adds everything to the scene. However, I'm running into problems when it comes to adding the camera to the scene again; I get Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException.



My code for wiping everything (which is called when the Reset button is pressed) is:


public void reload() {
   setup = false;
   DisplaySystem.getDisplaySystem().getRenderer().cleanup();
   DisplaySystem.getDisplaySystem().getCurrentContext().invalidateStates();                     
   DisplaySystem.getDisplaySystem().reset();
   DisplaySystem.getDisplaySystem().close();
   physicsSpace.delete();
   renderer.cleanup();
   root.detachAllChildren();
   doSetup();
}

I believe the cleanup methods (and others) are meant to be called when the display is closing…



Try just 'managing' the stuff, like just removing the root node children and such; basically the idea is to keep the display up and running (you are basically closing everything). 



This may not be the 'correct' way but it works well for me…



(You will probably need to handle releasing some of the resources yourself such as textures and such, or at least keep it in mind as you work…)

You can't have mulitple canvases in jME (you can with momoko_fans context system though); and I believe just creating a new one will lead to problems…



You will need to either use GameStates or you can just un-attach/attach everything from a 'root node' (ie control it with logic)…