Hi
I’m writing a JME app in an applet using eclipse, and after much nonsense with signing jars and suchlike I have it working. However the applet only works the first time it’s loaded in a browser. Investigating a bit I found that there were errors when it tried to restart the applet, which can be reproduced on the appletviewer.
I’ve reproduced the problem with the applets in jmetest.awt.applet so I don’t think there should be a need to post any of my code. When I run the applet it works fine, and then when I hit restart I get a NullPointerException:
java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glDeleteTextures(GL11.java:716)
at com.jme.scene.state.lwjgl.LWJGLTextureState.deleteAll(LWJGLTextureState.java:1457)
at com.jme.scene.Text.resetFontTexture(Text.java:226)
at com.jmex.awt.applet.SimpleJMEApplet.init(SimpleJMEApplet.java:127)
at sun.applet.AppletPanel.run(AppletPanel.java:425)
at java.lang.Thread.run(Thread.java:619)
I found a couple of topics here and here which mention this problem, but neither of the suggested fixes work for me.
Making the first suggested change to SimpleJMEApplet, if I put the Text.resetFontTexture() call inside the Callable created for doing setFrustumPerspective, I get a different error:
Exception in thread “AWT-EventQueue-1” java.lang.NullPointerException
at com.jme.scene.state.lwjgl.LWJGLZBufferState.enableDepthTest(LWJGLZBufferState.java:109)
at com.jme.scene.state.lwjgl.LWJGLZBufferState.apply(LWJGLZBufferState.java:67)
at com.jme.renderer.lwjgl.LWJGLRenderer.clearBuffers(LWJGLRenderer.java:482)
at com.jmex.awt.SimpleCanvasImpl.doRender(SimpleCanvasImpl.java:141)
at com.jmex.awt.lwjgl.LWJGLCanvas.paintGL(LWJGLCanvas.java:110)
at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:308)
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:4489)
at java.awt.Component.dispatchEvent(Component.java:4243)
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)
I do get some errors about not being able to install the lwjgl libs when running in the appletviewer (not in the browser), but since the applet runs anyway I’m guessing that it finds the libs in my classpath even though it can’t install them itself.
I also tried calling DisplaySystem.resetSystemProvider(); right before the createCanvas() call as suggested in the second topic, but that made no difference.
Can anyone suggest what I might try next to track down the problem? or something stupid I might have done to break it like this?
it seems to be a threading problem here. I added a start init / end init sysout and end init is never reached.
– applet is running –
– restart applet –
start init
doRender()
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at com.jme.scene.state.lwjgl.LWJGLBlendState.applyBlendEquations(LWJGLBlendState.java:114)
When a applet is restarted, init() is called, then from another thread doRender() gets called while we're still in init() and while we're recreating stuff.
So i think either init and doRender needs to be synchronized,
or maybe it enough to add a boolean isCreated and just reset the game logic once the applet is created?
@Override
public void init() {
if (isCreated) {
// just reset positions and stuff to reset your game here
return;
}
super.init();
isCreated = true;
}
Hey baldurk,
I've had the same problem. Unfortunately I don't perfect explanation or a quick fix for you. I had a number of problems getting jME working in applets and found myself going directly to LWJGL which doesn't seem to have the same problems. Then, I built up from there slowly and reintroducing jME. The result is a custom Loader and Canvas class. The loader is based on the LWJGL examples and the Canvas is based on the jME's LWJGLCanvas. You can do the same thing if you use a custom JMECanvasImplementor if you wanted to.
Anyway, Code Dump is right. It is a thread issue and its been as long as SimpleJMEApplet, but only causes the null pointer exception when you reload the applet and that is because your applet is using the same VM and all your static variables are still around from the first time you loaded. Anyway, you can dig around deeper if you want to, but if you want to fix the problem get the "resetFontTexture" call into the paintGL(). There is a onetime setup that the LWJGLCanvas uses you can do something like that if you want.
Anyway, I'm sorry for the late response. I rarely check these forum. If you have any more applet specific problems you can always post here and ping me at dev@lefty2shoes.com.
Good luck