Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game does not exit when non-daemon thread is running in the JVM #566

Open
MartinHaeusler opened this issue Jan 24, 2024 · 0 comments · May be fixed by #567
Open

Game does not exit when non-daemon thread is running in the JVM #566

MartinHaeusler opened this issue Jan 24, 2024 · 0 comments · May be fixed by #567
Assignees
Labels
bug Something isn't working topic:core

Comments

@MartinHaeusler
Copy link
Contributor

If we create a regular thread in Kotlin which keeps running, like so:

@RegisterClass
class MyButton : Button() {

    @RegisterFunction
    override fun _pressed() {
        thread {
            GD.print("Sleeping")
            Thread.sleep(TimeUnit.HOURS.toMillis(1))
            GD.print("Wake up!")
        }

    }
}

... then the game window will not exit properly when clicking on the window close ("x") button. Hitting the "stop" button in the editor still works.

The workaround is to declare the thread as a daemon thread:

    thread(daemon = true){
        // ...
    }

... as this will not prevent the JVM from exiting.

I don't think that this needs to have super high priority, but if a library would spawn threads (e.g. an async HTTP client might do that) and doesn't permit control over the creation of the thread, then this can become an issue.

Maybe this can be handled on the C++ side? It works when stopping the game via the godot editor "stop" button after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants