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

[3.x] Backport Accept global classes for MainLoop type in project settings #52438

Merged
merged 1 commit into from
Sep 17, 2021
Merged
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
21 changes: 18 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@ bool Main::start() {
}
}

String main_loop_type;
#ifdef TOOLS_ENABLED
if (doc_tool_path != "") {
Engine::get_singleton()->set_editor_hint(true); // Needed to instance editor-only classes for their default values
Expand Down Expand Up @@ -1661,6 +1660,7 @@ bool Main::start() {
if (editor) {
main_loop = memnew(SceneTree);
};
String main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "SceneTree");

if (test != "") {
#ifdef TOOLS_ENABLED
Expand Down Expand Up @@ -1699,8 +1699,23 @@ bool Main::start() {
return false;
}

} else {
main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "");
} else { // Not based on script path.
if (!editor && !ClassDB::class_exists(main_loop_type) && ScriptServer::is_global_class(main_loop_type)) {
String script_path = ScriptServer::get_global_class_path(main_loop_type);
Ref<Script> script_res = ResourceLoader::load(script_path, "Script", true);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Ref<Script> script_res = ResourceLoader::load(script_path);
+ Ref<Script> script_res = ResourceLoader::load(script_path, "Script", true);

script_res should be load without any cache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't matter much because not a lot of resources get loaded at engine startup to worry about this I guess.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the time, the loading of custom main loop is fine.

some times. if I clike Run Button very fast after opening the editor. then my custom main loop script seems load failed.

QQ20210907001802

After this error happening, script wont be reload until I reopen the editor.

tested by setting no_cache=true here still won't fix this problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this feature may just reveal editor problem. According to error, the base type is basically "", which probably means that editor settings could not get loaded (maybe when the file gets locked for reading, and cannot be read again until the previous Godot process shuts down completely).

StringName script_base = ScriptServer::get_global_class_native_base(main_loop_type);
Object *obj = ClassDB::instance(script_base);
MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
if (!script_loop) {
if (obj) {
memdelete(obj);
}
OS::get_singleton()->alert("Error: Invalid MainLoop script base type: " + script_base);
ERR_FAIL_V_MSG(false, vformat("The global class %s does not inherit from SceneTree or MainLoop.", main_loop_type));
}
script_loop->set_init_script(script_res);
main_loop = script_loop;
}
}

if (!main_loop && main_loop_type == "") {
Expand Down