Epsilia
Epsilia

Reputation: 108

LWJGL Game not properly ending

I currently have a simple problem with LWJGL right now. If I were to run my game, it does actually run everything correctly and it appears to close out correctly, but when I look inside my Task Manager, I notice that my game is taking up 25% CPU after I close it (about 2-3% when it's actually running) and I'm thinking that I may have missed something when ending the application.

My main function code:

public static void main(String[] args){
    try {
        init();
    }catch(LWJGLException e){
        System.out.println("LWJGLException\n");
        e.printStackTrace();
    }
    try{
        gameLoop();
    }catch(Exception ex){
        ex.printStackTrace();
    }finally{
        cleanup();
    }
}

cleanup:

public static void cleanup(){
    System.out.println("Running cleanup code.");
    Display.destroy();
    System.exit(0);
}

It does actually manage to read "Running cleanup code." My problem is that I don't know if there is something else I need to do to clear out all of the processes. This game is also using a single thread.

Upvotes: 5

Views: 1015

Answers (2)

luke
luke

Reputation: 4155

I have had the same problem on 64-bit windows. App haven't closed when Runtime Exception (or any other uncaught exception) occured. Probably reason was throwing an exception in an independent thread which effected in closing display window, but all other threads were still working. I came up with brute force solution: overriding Thread method.

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
         @Override
         public void uncaughtException (Thread thread, final Throwable ex) {
            ex.printStackTrace();
            Display.destroy();
            System.exit(0);
         }});

    new LwjglApplication(new StartScreen(application), cfg);

Upvotes: 0

Jasper Creyf
Jasper Creyf

Reputation: 36

There is nothing wrong with your code at all, I think. If your problem is what I think it is you wouldn't be able to immediately fix it.

Here are some basic questions you should ask your self. What OS are you using? What is your Java version and/or LWJGL version? (Updating them might help) Have you ever heard of/or played a game called Minecraft? If you are using Linux and seen this when closing Minecraft then that could be the problem you're having.

Upvotes: 1

Related Questions