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

fix: Kill existing user threads except main when closing engine #567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions harness/tests/src/main/kotlin/godot/tests/Invocation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ import godot.core.asStringName
import godot.core.dictionaryOf
import godot.core.variantArrayOf
import godot.extensions.getNodeAs
import godot.global.GD
import godot.registration.Range
import godot.signals.signal
import godot.tests.subpackage.OtherScript
import godot.util.RealT
import org.joda.time.DateTime
import kotlin.concurrent.thread

enum class TestEnum {
ENUM_1,
Expand Down Expand Up @@ -434,6 +436,13 @@ class Invocation : Node3D() {

init {
println("Hello Invocation!")

thread(name = "invocation_thread") {
while (true) {
GD.print("In thread: ${Thread.currentThread()}")
Thread.sleep(1000)
}
}
}

override fun _onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ internal class Bootstrap {
watchService?.close()
clearClassesCache()
serviceLoader.reload()
Thread.currentThread().threadGroup.interrupt()
}

private fun doInit(mainJar: URL, classLoader: ClassLoader?) {
Expand Down
11 changes: 6 additions & 5 deletions src/gd_kotlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,11 @@ void GDKotlin::finish() {
#endif
return;
}
auto env = jni::Jvm::current_env();

bootstrap->finish(env);

delete transfer_context;
transfer_context = nullptr;
delete bootstrap;
bootstrap = nullptr;

auto env = jni::Jvm::current_env();

TypeManager::get_instance().clear();

Expand All @@ -358,6 +355,10 @@ void GDKotlin::finish() {
garbage_collector_instance.call_void_method(env, clean_up_method_id);
}

bootstrap->finish(env);
delete bootstrap;
bootstrap = nullptr;

LongStringQueue::destroy();
BridgesManager::get_instance().delete_bridges();
TypeManager::destroy();
Expand Down
Loading