Swing Multiple Panels

I am developing an application with support for multicanvas rendering, using the classes posted in



http://www.jmonkeyengine.com/jmeforum/index.php?topic=7168.0



The application renders the same scene from 4 different point of view, as in the screenshot below:







It happens that if I initialize and add the four instances of my specialized JPanel rendering class (JMEPanel) in a certain order, everything works well, but changing the order sometimes results in an exception:



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at com.jme.renderer.lwjgl.LWJGLCamera.doFrustumChange(Unknown Source)
   at com.jme.renderer.lwjgl.LWJGLCamera.apply(Unknown Source)
   at com.jme.renderer.lwjgl.LWJGLCamera.<init>(Unknown Source)
   at com.jme.renderer.lwjgl.LWJGLRenderer.createCamera(Unknown Source)
   at jg.gizmo.rendering.jme.context.lwjgl.LWJGLContext.contextInit(LWJGLContext.java:243)
   at jg.gizmo.rendering.jme.context.lwjgl.LWJGLCanvas.run(LWJGLCanvas.java:104)
   at jg.gizmo.rendering.jme.context.lwjgl.LWJGLCanvas.initGL(LWJGLCanvas.java:113)
   at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:306)
   at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
   at sun.awt.RepaintArea.paint(RepaintArea.java:224)
   at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
   at java.awt.Component.dispatchEventImpl(Component.java:4486)
   at java.awt.Component.dispatchEvent(Component.java:4240)
   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)




This is how I initialize my JMEPanel, that contains a LWJGLCanvas of the type contained in the thread I linked at the top of my post:


   private void initComponents() {

      setLayout(new BorderLayout());
      try {
         if (JmeContext.get() != null) {
            // share with the previous context
            context = JmeContext.create(JmeContext.getDefaultImplementorClassName(), JmeContext.CONTEXT_CANVAS,
                  JmeContext.get());
         } else {
            context = JmeContext.create(JmeContext.getDefaultImplementorClassName(), JmeContext.CONTEXT_CANVAS);
         }
      } catch (InstantiationException ex) {
         ex.printStackTrace();
      }
      context.start();
      canvas = context.getCanvas();

      // System.out.println("Panel " + hashCode() + " - scene " + sceneId +
      // " - context is " + context.hashCode()
      // + " - canvas is " + canvas.hashCode());

      add(canvas, BorderLayout.CENTER);
   }



It seems that the problem is that the main DisplaySystem object is not coherent with the added classes. Any idea on the cause of this crash?

I had this problem before, I think. Try downloading the latest version of jme-context from the radakan svn:

http://sourceforge.net/svn/?group_id=154936



It's located in trunk/JMEContext