Skip to content

Commit 79897dd

Browse files
committed
Restore script class cache if removed
I have no idea why anyone would do this, but this fixes it. Fixes #72154. Depends on #72444 being merged to function properly.
1 parent e9de988 commit 79897dd

6 files changed

+23
-3
lines changed

core/config/project_settings.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ Array ProjectSettings::get_global_class_list() {
11371137

11381138
Ref<ConfigFile> cf;
11391139
cf.instantiate();
1140-
if (cf->load(get_project_data_path().path_join("global_script_class_cache.cfg")) == OK) {
1140+
if (cf->load(get_global_class_list_path()) == OK) {
11411141
script_classes = cf->get_value("", "list");
11421142
} else {
11431143
#ifndef TOOLS_ENABLED
@@ -1148,11 +1148,15 @@ Array ProjectSettings::get_global_class_list() {
11481148
return script_classes;
11491149
}
11501150

1151+
String ProjectSettings::get_global_class_list_path() const {
1152+
return get_project_data_path().path_join("global_script_class_cache.cfg");
1153+
}
1154+
11511155
void ProjectSettings::store_global_class_list(const Array &p_classes) {
11521156
Ref<ConfigFile> cf;
11531157
cf.instantiate();
11541158
cf->set_value("", "list", p_classes);
1155-
cf->save(get_project_data_path().path_join("global_script_class_cache.cfg"));
1159+
cf->save(get_global_class_list_path());
11561160
}
11571161

11581162
bool ProjectSettings::has_custom_feature(const String &p_feature) const {

core/config/project_settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class ProjectSettings : public Object {
143143
Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const;
144144
Array get_global_class_list();
145145
void store_global_class_list(const Array &p_classes);
146+
String get_global_class_list_path() const;
146147

147148
bool has_setting(String p_var) const;
148149
String localize_path(const String &p_path) const;

core/object/script_language.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ void ScriptServer::save_global_classes() {
369369
ProjectSettings::get_singleton()->store_global_class_list(gcarr);
370370
}
371371

372+
bool ScriptServer::has_global_classes() {
373+
return !global_classes.is_empty();
374+
}
375+
376+
String ScriptServer::get_global_class_cache_file_path() {
377+
return ProjectSettings::get_singleton()->get_global_class_list_path();
378+
}
379+
372380
////////////////////
373381

374382
Variant ScriptInstance::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {

core/object/script_language.h

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class ScriptServer {
9191
static void get_global_class_list(List<StringName> *r_global_classes);
9292
static void get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes);
9393
static void save_global_classes();
94+
static bool has_global_classes();
95+
static String get_global_class_cache_file_path();
9496

9597
static void init_languages();
9698
static void finish_languages();

editor/editor_file_system.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,11 @@ void EditorFileSystem::_update_script_classes() {
15911591
void EditorFileSystem::_update_pending_script_classes() {
15921592
if (!update_script_paths.is_empty()) {
15931593
_update_script_classes();
1594+
} else {
1595+
// In case the class cache file was removed somehow, regenerate it.
1596+
if (ScriptServer::has_global_classes() && !FileAccess::exists(ScriptServer::get_global_class_cache_file_path())) {
1597+
ScriptServer::save_global_classes();
1598+
}
15941599
}
15951600
}
15961601

editor/export/editor_export_platform.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
814814
HashSet<String> paths;
815815
Vector<String> path_remaps;
816816

817-
paths.insert(ProjectSettings::get_singleton()->get_project_data_path().path_join("global_script_class_cache.cfg"));
817+
paths.insert(ProjectSettings::get_singleton()->get_global_class_list_path());
818818
if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
819819
//find stuff
820820
_export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);

0 commit comments

Comments
 (0)