6
\$\begingroup\$

When I use Gdx.app.exit() the game window closes but the resources don't appear to be released and the app is still running.

For instance, to exit on when the escape key is pressed:

public boolean keyDown(int keycode) {

//...

    if (Gdx.input.isKeyPressed(Keys.ESCAPE))
        Gdx.app.exit();

The window closes, the dispose() method is called but Eclipse still reports that the app is open (because the terminate button is still available): Eclipse reports that the app is still running

If the app had exited properly, the path to the JVM would have <terminated> in front of it, and the red terminate button would be greyed out.

Also when I use hide() and then dispose():

@Override
public void hide() {
    dispose();

}

@Override
public void dispose() {
    map.dispose();
    ...
    playerHitbox.dispose();
    System.out.println("----- END OF OUTPUT -----");

}

The same thing happens. You have to terminate the app with the button provided by Eclipse, or in the release version use the kill command (or task manager).

So my question is, how can I properly exit the app so all resources are gracefully unloaded, the window hides and the process exits in LibGDX?

\$\endgroup\$
5
\$\begingroup\$

I found the solution!

In my DesktopLauncher class, I had set config.forceExit to false instead of true, which caused the app to exit incorrectly (keep the running in the background.)

You need to set config.forceExit to true

And there are no AL lib cleanup errors or native-related libraries having issues.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, it still works on 2021! That line of code must be placed after LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); Also I checked in terminal that there isn't anymore the process active. \$\endgroup\$ – user2342558 Feb 3 at 21:09
1
\$\begingroup\$

A simple System.exit(0); should do the trick. Depending on your project setup, Gdx.app.exit(); could be terminating the LibGDX app, and not the entire program, where an added system exit will kill the runtime.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, I've tried System.exit(0) and while it does work it gives me an AL lib: alc_cleanup: 1 device not closed error, which I've read is harmless but I'd prefer to exit the app without any errors. I'll use this as a temporary fix in the mean time. Thanks ;) \$\endgroup\$ – Matt Y Oct 1 '15 at 3:33
  • \$\begingroup\$ It's now giving my other errors like: pure virtual method called [new line] terminate called without an active exception so I think I'll avoid it. \$\endgroup\$ – Matt Y Oct 1 '15 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.