Skip to content

Commit a4ed24a

Browse files
committed
Merge pull request #98041 from Hilderin/fix-lost-gdextensions-on-startup
Fix loss of gdextension on editor startup
2 parents 7815ccb + fbd1643 commit a4ed24a

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

core/io/resource_format_binary.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,11 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
12681268
return;
12691269
}
12701270

1271+
// res files not supported for GDExtension.
1272+
if (p_type == "GDExtension") {
1273+
return;
1274+
}
1275+
12711276
List<String> extensions;
12721277
ClassDB::get_extensions_for_type(p_type, &extensions);
12731278

editor/editor_file_system.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,16 @@ void EditorFileSystem::_first_scan_filesystem() {
248248
ep.step(TTR("Scanning file structure..."), 0, true);
249249
nb_files_total = _scan_new_dir(first_scan_root_dir, d);
250250

251+
// Preloading GDExtensions file extensions to prevent looping on all the resource loaders
252+
// for each files in _first_scan_process_scripts.
253+
List<String> gdextension_extensions;
254+
ResourceLoader::get_recognized_extensions_for_type("GDExtension", &gdextension_extensions);
255+
251256
// This loads the global class names from the scripts and ensures that even if the
252257
// global_script_class_cache.cfg was missing or invalid, the global class names are valid in ScriptServer.
253258
// At the same time, to prevent looping multiple times in all files, it looks for extensions.
254259
ep.step(TTR("Loading global class names..."), 1, true);
255-
_first_scan_process_scripts(first_scan_root_dir, existing_class_names, extensions);
260+
_first_scan_process_scripts(first_scan_root_dir, gdextension_extensions, existing_class_names, extensions);
256261

257262
// Removing invalid global class to prevent having invalid paths in ScriptServer.
258263
_remove_invalid_global_class_names(existing_class_names);
@@ -276,41 +281,46 @@ void EditorFileSystem::_first_scan_filesystem() {
276281
ep.step(TTR("Starting file scan..."), 5, true);
277282
}
278283

279-
void EditorFileSystem::_first_scan_process_scripts(const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions) {
284+
void EditorFileSystem::_first_scan_process_scripts(const ScannedDirectory *p_scan_dir, List<String> &p_gdextension_extensions, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions) {
280285
for (ScannedDirectory *scan_sub_dir : p_scan_dir->subdirs) {
281-
_first_scan_process_scripts(scan_sub_dir, p_existing_class_names, p_extensions);
286+
_first_scan_process_scripts(scan_sub_dir, p_gdextension_extensions, p_existing_class_names, p_extensions);
282287
}
283288

284289
for (const String &scan_file : p_scan_dir->files) {
285290
// Optimization to skip the ResourceLoader::get_resource_type for files
286291
// that are not scripts. Some loader get_resource_type methods read the file
287292
// which can be very slow on large projects.
288-
String ext = scan_file.get_extension().to_lower();
293+
const String ext = scan_file.get_extension().to_lower();
289294
bool is_script = false;
290295
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
291296
if (ScriptServer::get_language(i)->get_extension() == ext) {
292297
is_script = true;
293298
break;
294299
}
295300
}
296-
if (!is_script) {
297-
continue; // Not a script.
298-
}
301+
if (is_script) {
302+
const String path = p_scan_dir->full_path.path_join(scan_file);
303+
const String type = ResourceLoader::get_resource_type(path);
299304

300-
String path = p_scan_dir->full_path.path_join(scan_file);
301-
String type = ResourceLoader::get_resource_type(path);
305+
if (ClassDB::is_parent_class(type, SNAME("Script"))) {
306+
String script_class_extends;
307+
String script_class_icon_path;
308+
String script_class_name = _get_global_script_class(type, path, &script_class_extends, &script_class_icon_path);
309+
_register_global_class_script(path, path, type, script_class_name, script_class_extends, script_class_icon_path);
302310

303-
if (ClassDB::is_parent_class(type, SNAME("Script"))) {
304-
String script_class_extends;
305-
String script_class_icon_path;
306-
String script_class_name = _get_global_script_class(type, path, &script_class_extends, &script_class_icon_path);
307-
_register_global_class_script(path, path, type, script_class_name, script_class_extends, script_class_icon_path);
311+
if (!script_class_name.is_empty()) {
312+
p_existing_class_names.insert(script_class_name);
313+
}
314+
}
315+
}
308316

309-
if (!script_class_name.is_empty()) {
310-
p_existing_class_names.insert(script_class_name);
317+
// Check for GDExtensions.
318+
if (p_gdextension_extensions.find(ext)) {
319+
const String path = p_scan_dir->full_path.path_join(scan_file);
320+
const String type = ResourceLoader::get_resource_type(path);
321+
if (type == SNAME("GDExtension")) {
322+
p_extensions.insert(path);
311323
}
312-
} else if (type == SNAME("GDExtension")) {
313-
p_extensions.insert(path);
314324
}
315325
}
316326
}

editor/editor_file_system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class EditorFileSystem : public Node {
191191

192192
void _scan_filesystem();
193193
void _first_scan_filesystem();
194-
void _first_scan_process_scripts(const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions);
194+
void _first_scan_process_scripts(const ScannedDirectory *p_scan_dir, List<String> &p_gdextension_extensions, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions);
195195

196196
HashSet<String> late_update_files;
197197

scene/resources/resource_format_text.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,8 @@ void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &
14311431
p_extensions->push_back("tscn");
14321432
}
14331433

1434-
// Don't allow .tres for PackedScenes.
1435-
if (p_type != "PackedScene") {
1434+
// Don't allow .tres for PackedScenes or GDExtension.
1435+
if (p_type != "PackedScene" && p_type != "GDExtension") {
14361436
p_extensions->push_back("tres");
14371437
}
14381438
}

0 commit comments

Comments
 (0)