I keep getting a null pointer on the line indicated wit -->
tex[0].setEnabled(true);
--> tex[0].apply();
That's (almost) impossible! Could rebuild your project, then review/post the stacktrace? AFAIK there's very little chance that tex[0] is fine for setEnabled(), but the very next line, it is null. Unless you have overridden Texture.setEnabled() with something nasty. Maybe you have missed a line, or several, from your stacktrace because System.err was interrupted by System.out, or someting?
Sorry, Momoko_Fan, but that doesn't really relate to the problem, which wasn't crashing due to threading issues, but a NullPointerException. Also, how do you know that the code is not run in a GL context? This is about LensFlare, and last time I looked at it, TestLensFlare had the textures loaded in exactly that way - the apply() calls are there to load the textures into the graphics card, I'm not entirely sure if that is only a pre-caching sort of thing, or even neccessary.
The NullPointerException is due to the thread being out of context. It is entirely possible that he is using StandardGame (as many others) and so he is likley to be out of the context.
The apply calls should only be made by the renderer to apply the state into GL; doc for RenderState.apply():
This function is defined in the RenderState that is actually used by the Renderer. It contains the code that, when executed, applies the render state for the given render system. This should only be called internally and not by users directly.
I'm using standardgame, and this stuff is located in a gamestate, which is afaik in the opengl thread. Whenever I do not use apply, the lens flares won't show up.
I did not override texture stuff.
I'll try what TestLensFlares gives, and I'll post the stack trace.
Whenever I do not use apply, the lens flares won't show up.
But apply causes a crash? How is that possible to use it then?
I believe that I still know the difference between seeing lens flares and not seeing lens flares, right? I don't use apply (commented it out) and no lens flares appeared.
Just because it's an NPE does not mean it is not a threading error. In fact, if it is an NPE anywhere inside of the jME code, in the majority of cases it is a GL thread problem.