Some JME questions

Hi,



I noticed that if the render thread stops because of an error, or if you press the close button of my game, the thread that handles sending/recieving of multiplayer messages keeps running. This doesn’t prevent you from connecting again, but it’s a useless thing which uses some of your CPU and ram.Is there a way to mark that thread as deamon, so that it will stop as soon as the render thread stops.



It would also be useful if I control what happens if the player presses the close button (for a popup to ask if you are sure that you want to close, and to terminate multiplayer propperly etc.)



What I also noticed is that during multiplayer, when I’m the only one online, It works well, but when other players join, I sometimes get an error, and the strange part abouth the error is that I have not written any of the classes that appear in the stack trace, those are all internal JME classes and internal java classes. Is there a way to fix this error? It seems to be physics-related, because the stack trace starts with some bullet classes.



A simular bug in my game as the above one: nifty gui sometimes fails to handle a mouse event when I click the login button. When I use tab to select the button, than press enter or space, it doesn’t happen. simular to the above, it only happens at random times, and the stack trace doesn’t go trough any of my classes.



I really hope you can give some more information about this.



Many thanks in advance.

I think more context (and things like stack traces) are going to be needed before anyone can really reply in detail to your questions…

Override Application.close() or destroy() to shut down stuff when the app lifecycle ends.

1 Like

Yeah, what normen says.



The client’s write thread is not daemon because I wanted to give it the best chance to get a complete message out. So you have to shut down networking specifically when the app closes… and normen’s “override destroy” approach is the safest.



Also acceptable is to use an AppState’s cleanup method… if you are already using app states to manage your code.

Thanks abouth the destroy method. It works.



I’m now going to try to do the glitch again, and I’l copy and paste the stack trace here.

I got a stack trace of someone else who was playing my game:



[java]miku:dist julien$ java -jar MyGame.jar -Xmx2048M -Xms2048M

Sending login request…

Login sucessful.

Inventory geladen.

Bezig met initialiseren…

a

Bezig met laden…

(0.77662337, 0.8999989, 1.3271077)

(0.92662334, 0.8999989, 1.1771077)

(0.13636361, 0.0, -0.13636361)

TEST

TEST

Cinematics initialized

23 juil. 2012 19:39:39 com.jme3.app.Application handleError

GRAVE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at de.lessvoid.nifty.elements.Element.canHandleInteraction(Element.java:1474)

at de.lessvoid.nifty.elements.Element.mouseEvent(Element.java:1405)

at de.lessvoid.nifty.screen.MouseOverHandler.processMouseEvent(MouseOverHandler.java:101)

at de.lessvoid.nifty.screen.Screen.forwardMouseEventToLayers(Screen.java:360)

at de.lessvoid.nifty.screen.Screen.mouseEvent(Screen.java:336)

at de.lessvoid.nifty.Nifty.forwardMouseEventToScreen(Nifty.java:266)

at de.lessvoid.nifty.Nifty.update(Nifty.java:250)

at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:92)

at com.jme3.input.InputManager.processQueue(InputManager.java:792)

at com.jme3.input.InputManager.update(InputManager.java:856)

at com.jme3.app.Application.update(Application.java:598)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)

at java.lang.Thread.run(Thread.java:680)

miku:dist julien$[/java]



I haven’t touched any of the classes listed in the stack trace, and this error happened at a random time.

Do you ever make any changes to the scene graph or nifty screens from a thread under than the render thread?



Having said that, that stack trace looks familiar. I seem to remember getting something similar when I had malformed nifty screens. Try trimming your screens down to the bare minimum and then add things a bit at a time to see what causes the exception.

an other question, when the openGL window loses focus, the game freezes. Is there a way to stop this from happening? I tried looking trough everything of the appsettings, but I didn’t find anything to stop this.

@beniboy said:
an other question, when the openGL window loses focus, the game freezes. Is there a way to stop this from happening? I tried looking trough everything of the appsettings, but I didn't find anything to stop this.


You mean the app pauses when it loses focus?

http://hub.jmonkeyengine.org/javadoc/com/jme3/app/Application.html#setPauseOnLostFocus(boolean)

That worked, thanks