Strange behaviour in eclipse (RCP)

I am experimenting around with context switiching in eclipse RCp and I stumbled upon a very strange behaviour.

I have the followoing code snipplet:


   @Override
   public void run() {

      ((SWTDisplaySystem) DisplaySystem.getDisplaySystem())
      .switchContext(canvasList);




That gives me

Exception in thread "Thread-4" java.lang.NullPointerException
at com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.isSupported(Unknown Source)
at com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.<init>(Unknown Source)
at com.jme.renderer.lwjgl.LWJGLRenderer.createGLSLShaderObjectsState(Unknown Source)
at com.jme.renderer.Renderer.createState(Unknown Source)
at com.jme.renderer.RenderContext.setupRecords(Unknown Source)
at com.jme.system.lwjgl.LWJGLDisplaySystem.switchContext(Unknown Source)
at com.ether.sandbox.view.RenderThread.run(RenderThread.java:69)



Now I move the switchContext line to the end of the constructor and suddenly it works.
In both cases I call the Thread with

RenderThread rendy = new RenderThread(Display.getCurrent(), canvas,
root);
rendy.start();


That means it shouldn't matter where I put that line as the order doesn't change.
Does anybody have an idea what that could be??

The only thing that comes to mind is that this is not being run in the GL thread, but I guess you could have figured out if that was the case…  :?

If that is the case… then you should probably try wrapping your switchContext call with some locking, or putting it in the TaskQueue

You were absolutely right.

I got messed up with java basics (darn):

call in constructor doesn't have same thread context as call in run.

darn