Skip to content

Commit f0ac180

Browse files
authored
utopia-riseGH-842 Fix thread context classloader (utopia-rise#848)
1 parent 90eb483 commit f0ac180

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

kt/godot-library/godot-core-library/src/main/kotlin/godot/runtime/Bootstrap.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ internal class Bootstrap {
3333
}
3434

3535
fun finish() {
36-
Thread.currentThread().contextClassLoader = null
3736
clearClassesCache()
3837
serviceLoader.reload()
3938
}

src/gd_kotlin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ bool GDKotlin::load_bootstrap() {
251251

252252
JVM_LOG_VERBOSE("Loading bootstrap jar: %s", bootstrap_jar);
253253
bootstrap_class_loader = ClassLoader::create_instance(env, bootstrap_jar, jni::JObject(nullptr));
254+
255+
// set context classloader to bootstrap initially
254256
bootstrap_class_loader->set_as_context_loader(env);
255257
}
256258

@@ -318,6 +320,9 @@ bool GDKotlin::load_user_code() {
318320
bootstrap_class_loader->get_wrapped()
319321
);
320322

323+
// update context classloader to use usercode jar
324+
user_class_loader->set_as_context_loader(env);
325+
321326
bootstrap->init_jar(env, user_class_loader->get_wrapped());
322327
delete user_class_loader;
323328
return FileAccess::exists(user_code_path);
@@ -326,6 +331,10 @@ bool GDKotlin::load_user_code() {
326331

327332
void GDKotlin::unload_user_code() {
328333
jni::Env env {jni::Jvm::current_env()};
334+
335+
// reset context classloader to bootstrap
336+
bootstrap_class_loader->set_as_context_loader(env);
337+
329338
bootstrap->finish(env);
330339
TypeManager::get_instance().clear();
331340
jar.unref();

0 commit comments

Comments
 (0)