Problem with JWJGLOffScreenRenderer throwing null pointer exception

i have an environment that i want to add new viewports into by pressing a JButton. The code i have works if you hard code my addViewPort method into the initial setup but fails if it is tried to be added once the environment has been initialized.

 public void addViewportPanel()

//      System.out.println(DisplaySystem.getDisplaySystem());

      osRenderer.add(((LWJGLDisplaySystem) DisplaySystem.getDisplaySystem()).createOffscreenRenderer(320, 320));
      osRenderer.get(numOfViewports).setBackgroundColor(new ColorRGBA(0f, 0f, 0f, 1f));
      CameraNode temp2;
      temp2 = new CameraNode("Camera Node Offscreen", osRenderer.get(numOfViewports).getCamera());
      temp2.setLocalTranslation(new Vector3f(0, 50, 50));
      temp2.lookAt(Vector3f.ZERO, Vector3f.UNIT_Z);
      temp2.updateGeometricState(0, true);
      OffScreenViewPort temp1;
      temp1 = new OffScreenViewPort(camNode.get(numOfViewports));
      temp1.setPreferredSize(new Dimension(320, 320));
      JFrame tempJFrame = new JFrame();
      tempJFrame.setLayout(new GridLayout(1, 1));
      tempJFrame.setLocation(0, 0);

The exception is thrown by the LWJGLOffScreenRenderer when it is being initialized. any suggestions on what the problem might be?

My guess would be that you need to run your method from the opengl thread.

Have a look here:

The code you want is the one using Callable.

That worked perfectly thank you!