Stop function is not called

Hi folks!
In a normal instance of a class that extends SimpleApplication i added this code:
@Override
public void stop() {
String userHome = System.getProperty(“user.home”);
BinaryExporter exporter = BinaryExporter.getInstance();
File file = new File(userHome+“all.j3o”);
try {
exporter.save(rootNode, file);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, “Error: Failed to save game!”, ex);
}
super.stop(); // continue quitting the game
}
According to this page (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:save_and_load) the function stop is called when the window is closed.
Saving the root node dosn’t seem to work so i tried to debug the code and noticed that this function is never called …
is it my false understanding and i have to call the stop function myself when the window is closed (if so how do i access this event? ), or why is this issue appearing?
Thanks for any help

I’ve checked Stop function is called both on Windows and Linux. And it does when you press “escape”.
However it is not called when closing the window.

I suspect the event is not the same…

1 Like

Thanks
Well my window dosnt close when i press escape,
should it automaticly do this or did you add the call to the stopfunction in the actionlistener for the escapekey??
And how can i controll what happens when the user closes the window?

Thanks for any help

I don’t know what special thing is needed to detect app shutdown at the Application level but the app states seem to always have their cleanup() methods called no matter how the app is closed. At least this is true in Mythruna where I have to close the database and stuff.

Arguably, an app state is a better way to handle this anyway.

Just as an aside, if you are saving the root node to implement some sort of save game feature then you will end up with lots of trouble down the road. 1) your save games potentially break with each new JME update. 2) you have to put complicated code in to make sure that all of your nodes get the latest versions of your controls and other game logic.

It’s better to save the game state itself rather than the visualization of that game state.

2 Likes

There’s also destroy() that can be used to detect when the application is closing.

Use a simple system.out.println('Called from methodName"); in each of those methods and which one you want to handle/how to handle it depending on how it’s triggered.

That’s one way to do it.

Thanks !

@pspeed said: It's better to save the game state itself rather than the visualization of that game state.

Not so sure about that because i am writing an multiplayereditor. Saving from this editor and loading in the actual game is faster if i only save the visulizationinformation and not the usercamera etc (and uses less discspace too, for sharing maps etc)

@pspeed said:

your save games potentially break with each new JME update.


I don’t quite know what you mean…
Does that mean that if i create a map, save it as a node and load it with a programm created by a new version of jme3 that it might not recognize the j3o file properly because the format might be changed?
So how do i save my sceneObjects and sounds etc in one file with the least possible unnecessary information in it for high efficiency?

(Another Problem)
in this example https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:save_and_load
System.getProperty(“user.home”); gets the path -> “C:\Users\username” but im quite shore that propably the assetsfolder path is wanted… (function dosn’t work)
Is this because i have a wrong import and the wrong System instance is beeing used or why am i having this Problem?

Any help is appreachiated