Skip to content

Commit 72d9ebb

Browse files
committed
Revert "Merge pull request godotengine#93972 from Hilderin/fix-editor-needs-restart-after-adding-gdextensions"
This reverts commit f0ee0bd, reversing changes made to b310e5e.
1 parent db66bd3 commit 72d9ebb

10 files changed

+65
-197
lines changed

core/extension/gdextension_manager.cpp

+6-88
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@
3232

3333
#include "core/extension/gdextension_compat_hashes.h"
3434
#include "core/extension/gdextension_library_loader.h"
35-
#include "core/io/dir_access.h"
3635
#include "core/io/file_access.h"
3736
#include "core/object/script_language.h"
3837

39-
GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal(const Ref<GDExtension> &p_extension, bool p_first_load) {
38+
GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal(const Ref<GDExtension> &p_extension) {
4039
if (level >= 0) { // Already initialized up to some level.
41-
int32_t minimum_level = 0;
42-
if (!p_first_load) {
43-
minimum_level = p_extension->get_minimum_library_initialization_level();
44-
if (minimum_level < MIN(level, GDExtension::INITIALIZATION_LEVEL_SCENE)) {
45-
return LOAD_STATUS_NEEDS_RESTART;
46-
}
40+
int32_t minimum_level = p_extension->get_minimum_library_initialization_level();
41+
if (minimum_level < MIN(level, GDExtension::INITIALIZATION_LEVEL_SCENE)) {
42+
return LOAD_STATUS_NEEDS_RESTART;
4743
}
4844
// Initialize up to current level.
4945
for (int32_t i = minimum_level; i <= level; i++) {
@@ -55,20 +51,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal(cons
5551
gdextension_class_icon_paths[kv.key] = kv.value;
5652
}
5753

58-
#ifdef TOOLS_ENABLED
59-
// Signals that a new extension is loaded so GDScript can register new class names.
60-
emit_signal("extension_loaded", p_extension);
61-
#endif
62-
6354
return LOAD_STATUS_OK;
6455
}
6556

6657
GDExtensionManager::LoadStatus GDExtensionManager::_unload_extension_internal(const Ref<GDExtension> &p_extension) {
67-
#ifdef TOOLS_ENABLED
68-
// Signals that a new extension is unloading so GDScript can unregister class names.
69-
emit_signal("extension_unloading", p_extension);
70-
#endif
71-
7258
if (level >= 0) { // Already initialized up to some level.
7359
// Deinitialize down from current level.
7460
for (int32_t i = level; i >= GDExtension::INITIALIZATION_LEVEL_CORE; i--) {
@@ -103,7 +89,7 @@ GDExtensionManager::LoadStatus GDExtensionManager::load_extension_with_loader(co
10389
return LOAD_STATUS_FAILED;
10490
}
10591

106-
LoadStatus status = _load_extension_internal(extension, true);
92+
LoadStatus status = _load_extension_internal(extension);
10793
if (status != LOAD_STATUS_OK) {
10894
return status;
10995
}
@@ -149,7 +135,7 @@ GDExtensionManager::LoadStatus GDExtensionManager::reload_extension(const String
149135
return LOAD_STATUS_FAILED;
150136
}
151137

152-
status = _load_extension_internal(extension, false);
138+
status = _load_extension_internal(extension);
153139
if (status != LOAD_STATUS_OK) {
154140
return status;
155141
}
@@ -288,72 +274,6 @@ void GDExtensionManager::reload_extensions() {
288274
#endif
289275
}
290276

291-
bool GDExtensionManager::ensure_extensions_loaded(const HashSet<String> &p_extensions) {
292-
Vector<String> extensions_added;
293-
Vector<String> extensions_removed;
294-
295-
for (const String &E : p_extensions) {
296-
if (!is_extension_loaded(E)) {
297-
extensions_added.push_back(E);
298-
}
299-
}
300-
301-
Vector<String> loaded_extensions = get_loaded_extensions();
302-
for (const String &loaded_extension : loaded_extensions) {
303-
if (!p_extensions.has(loaded_extension)) {
304-
// The extension may not have a .gdextension file.
305-
const Ref<GDExtension> extension = GDExtensionManager::get_singleton()->get_extension(loaded_extension);
306-
if (!extension->get_loader()->library_exists()) {
307-
extensions_removed.push_back(loaded_extension);
308-
}
309-
}
310-
}
311-
312-
String extension_list_config_file = GDExtension::get_extension_list_config_file();
313-
if (p_extensions.size()) {
314-
if (extensions_added.size() || extensions_removed.size()) {
315-
// Extensions were added or removed.
316-
Ref<FileAccess> f = FileAccess::open(extension_list_config_file, FileAccess::WRITE);
317-
for (const String &E : p_extensions) {
318-
f->store_line(E);
319-
}
320-
}
321-
} else {
322-
if (loaded_extensions.size() || FileAccess::exists(extension_list_config_file)) {
323-
// Extensions were removed.
324-
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
325-
da->remove(extension_list_config_file);
326-
}
327-
}
328-
329-
bool needs_restart = false;
330-
for (const String &extension : extensions_added) {
331-
GDExtensionManager::LoadStatus st = GDExtensionManager::get_singleton()->load_extension(extension);
332-
if (st == GDExtensionManager::LOAD_STATUS_NEEDS_RESTART) {
333-
needs_restart = true;
334-
}
335-
}
336-
337-
for (const String &extension : extensions_removed) {
338-
GDExtensionManager::LoadStatus st = GDExtensionManager::get_singleton()->unload_extension(extension);
339-
if (st == GDExtensionManager::LOAD_STATUS_NEEDS_RESTART) {
340-
needs_restart = true;
341-
}
342-
}
343-
344-
#ifdef TOOLS_ENABLED
345-
if (extensions_added.size() || extensions_removed.size()) {
346-
// Emitting extensions_reloaded so EditorNode can reload Inspector and regenerate documentation.
347-
emit_signal("extensions_reloaded");
348-
349-
// Reload all scripts to clear out old references.
350-
callable_mp_static(&GDExtensionManager::_reload_all_scripts).call_deferred();
351-
}
352-
#endif
353-
354-
return needs_restart;
355-
}
356-
357277
GDExtensionManager *GDExtensionManager::get_singleton() {
358278
return singleton;
359279
}
@@ -374,8 +294,6 @@ void GDExtensionManager::_bind_methods() {
374294
BIND_ENUM_CONSTANT(LOAD_STATUS_NEEDS_RESTART);
375295

376296
ADD_SIGNAL(MethodInfo("extensions_reloaded"));
377-
ADD_SIGNAL(MethodInfo("extension_loaded", PropertyInfo(Variant::OBJECT, "extension", PROPERTY_HINT_RESOURCE_TYPE, "GDExtension")));
378-
ADD_SIGNAL(MethodInfo("extension_unloading", PropertyInfo(Variant::OBJECT, "extension", PROPERTY_HINT_RESOURCE_TYPE, "GDExtension")));
379297
}
380298

381299
GDExtensionManager *GDExtensionManager::singleton = nullptr;

core/extension/gdextension_manager.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class GDExtensionManager : public Object {
5454
};
5555

5656
private:
57-
LoadStatus _load_extension_internal(const Ref<GDExtension> &p_extension, bool p_first_load);
57+
LoadStatus _load_extension_internal(const Ref<GDExtension> &p_extension);
5858
LoadStatus _unload_extension_internal(const Ref<GDExtension> &p_extension);
5959

6060
#ifdef TOOLS_ENABLED
@@ -85,7 +85,6 @@ class GDExtensionManager : public Object {
8585

8686
void load_extensions();
8787
void reload_extensions();
88-
bool ensure_extensions_loaded(const HashSet<String> &p_extensions);
8988

9089
GDExtensionManager();
9190
~GDExtensionManager();

core/object/class_db.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,6 @@ void ClassDB::get_extensions_class_list(List<StringName> *p_classes) {
267267

268268
p_classes->sort_custom<StringName::AlphCompare>();
269269
}
270-
271-
void ClassDB::get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes) {
272-
OBJTYPE_RLOCK;
273-
274-
for (const KeyValue<StringName, ClassInfo> &E : classes) {
275-
if (E.value.api != API_EXTENSION && E.value.api != API_EDITOR_EXTENSION) {
276-
continue;
277-
}
278-
if (!E.value.gdextension || E.value.gdextension->library != p_extension.ptr()) {
279-
continue;
280-
}
281-
p_classes->push_back(E.key);
282-
}
283-
284-
p_classes->sort_custom<StringName::AlphCompare>();
285-
}
286270
#endif
287271

288272
void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {

core/object/class_db.h

-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ class ClassDB {
289289
static void get_class_list(List<StringName> *p_classes);
290290
#ifdef TOOLS_ENABLED
291291
static void get_extensions_class_list(List<StringName> *p_classes);
292-
static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
293292
static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
294293
#endif
295294
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);

doc/classes/GDExtensionManager.xml

-14
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,6 @@
5656
</method>
5757
</methods>
5858
<signals>
59-
<signal name="extension_loaded">
60-
<param index="0" name="extension" type="GDExtension" />
61-
<description>
62-
Emitted after the editor has finished loading a new extension.
63-
[b]Note:[/b] This signal is only emitted in editor builds.
64-
</description>
65-
</signal>
66-
<signal name="extension_unloading">
67-
<param index="0" name="extension" type="GDExtension" />
68-
<description>
69-
Emitted before the editor starts unloading an extension.
70-
[b]Note:[/b] This signal is only emitted in editor builds.
71-
</description>
72-
</signal>
7359
<signal name="extensions_reloaded">
7460
<description>
7561
Emitted after the editor has finished reloading one or more extensions.

editor/editor_file_system.cpp

+54-15
Original file line numberDiff line numberDiff line change
@@ -243,27 +243,18 @@ void EditorFileSystem::_first_scan_filesystem() {
243243
first_scan_root_dir = memnew(ScannedDirectory);
244244
first_scan_root_dir->full_path = "res://";
245245
HashSet<String> existing_class_names;
246-
HashSet<String> extensions;
247246

248247
ep.step(TTR("Scanning file structure..."), 0, true);
249248
nb_files_total = _scan_new_dir(first_scan_root_dir, d);
250249

251250
// This loads the global class names from the scripts and ensures that even if the
252251
// global_script_class_cache.cfg was missing or invalid, the global class names are valid in ScriptServer.
253-
// At the same time, to prevent looping multiple times in all files, it looks for extensions.
254252
ep.step(TTR("Loading global class names..."), 1, true);
255-
_first_scan_process_scripts(first_scan_root_dir, existing_class_names, extensions);
253+
_first_scan_process_scripts(first_scan_root_dir, existing_class_names);
256254

257255
// Removing invalid global class to prevent having invalid paths in ScriptServer.
258256
_remove_invalid_global_class_names(existing_class_names);
259257

260-
// Processing extensions to add new extensions or remove invalid ones.
261-
// Important to do it in the first scan so custom types, new class names, custom importers, etc...
262-
// from extensions are ready to go before plugins, autoloads and resources validation/importation.
263-
// At this point, a restart of the editor should not be needed so we don't use the return value.
264-
ep.step(TTR("Verifying GDExtensions..."), 2, true);
265-
GDExtensionManager::get_singleton()->ensure_extensions_loaded(extensions);
266-
267258
// Now that all the global class names should be loaded, create autoloads and plugins.
268259
// This is done after loading the global class names because autoloads and plugins can use
269260
// global class names.
@@ -276,9 +267,9 @@ void EditorFileSystem::_first_scan_filesystem() {
276267
ep.step(TTR("Starting file scan..."), 5, true);
277268
}
278269

279-
void EditorFileSystem::_first_scan_process_scripts(const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names, HashSet<String> &p_extensions) {
270+
void EditorFileSystem::_first_scan_process_scripts(const ScannedDirectory *p_scan_dir, HashSet<String> &p_existing_class_names) {
280271
for (ScannedDirectory *scan_sub_dir : p_scan_dir->subdirs) {
281-
_first_scan_process_scripts(scan_sub_dir, p_existing_class_names, p_extensions);
272+
_first_scan_process_scripts(scan_sub_dir, p_existing_class_names);
282273
}
283274

284275
for (const String &scan_file : p_scan_dir->files) {
@@ -309,8 +300,6 @@ void EditorFileSystem::_first_scan_process_scripts(const ScannedDirectory *p_sca
309300
if (!script_class_name.is_empty()) {
310301
p_existing_class_names.insert(script_class_name);
311302
}
312-
} else if (type == SNAME("GDExtension")) {
313-
p_extensions.insert(path);
314303
}
315304
}
316305
}
@@ -3300,7 +3289,57 @@ bool EditorFileSystem::_scan_extensions() {
33003289

33013290
_scan_extensions_dir(d, extensions);
33023291

3303-
return GDExtensionManager::get_singleton()->ensure_extensions_loaded(extensions);
3292+
//verify against loaded extensions
3293+
3294+
Vector<String> extensions_added;
3295+
Vector<String> extensions_removed;
3296+
3297+
for (const String &E : extensions) {
3298+
if (!GDExtensionManager::get_singleton()->is_extension_loaded(E)) {
3299+
extensions_added.push_back(E);
3300+
}
3301+
}
3302+
3303+
Vector<String> loaded_extensions = GDExtensionManager::get_singleton()->get_loaded_extensions();
3304+
for (int i = 0; i < loaded_extensions.size(); i++) {
3305+
if (!extensions.has(loaded_extensions[i])) {
3306+
// The extension may not have a .gdextension file.
3307+
if (!FileAccess::exists(loaded_extensions[i])) {
3308+
extensions_removed.push_back(loaded_extensions[i]);
3309+
}
3310+
}
3311+
}
3312+
3313+
String extension_list_config_file = GDExtension::get_extension_list_config_file();
3314+
if (extensions.size()) {
3315+
if (extensions_added.size() || extensions_removed.size()) { //extensions were added or removed
3316+
Ref<FileAccess> f = FileAccess::open(extension_list_config_file, FileAccess::WRITE);
3317+
for (const String &E : extensions) {
3318+
f->store_line(E);
3319+
}
3320+
}
3321+
} else {
3322+
if (loaded_extensions.size() || FileAccess::exists(extension_list_config_file)) { //extensions were removed
3323+
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
3324+
da->remove(extension_list_config_file);
3325+
}
3326+
}
3327+
3328+
bool needs_restart = false;
3329+
for (int i = 0; i < extensions_added.size(); i++) {
3330+
GDExtensionManager::LoadStatus st = GDExtensionManager::get_singleton()->load_extension(extensions_added[i]);
3331+
if (st == GDExtensionManager::LOAD_STATUS_NEEDS_RESTART) {
3332+
needs_restart = true;
3333+
}
3334+
}
3335+
for (int i = 0; i < extensions_removed.size(); i++) {
3336+
GDExtensionManager::LoadStatus st = GDExtensionManager::get_singleton()->unload_extension(extensions_removed[i]);
3337+
if (st == GDExtensionManager::LOAD_STATUS_NEEDS_RESTART) {
3338+
needs_restart = true;
3339+
}
3340+
}
3341+
3342+
return needs_restart;
33043343
}
33053344

33063345
void EditorFileSystem::_bind_methods() {

editor/editor_file_system.h

+1-1
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, HashSet<String> &p_existing_class_names);
195195

196196
HashSet<String> late_update_files;
197197

editor/editor_node.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,6 @@ void EditorNode::_gdextensions_reloaded() {
485485
// In case the developer is inspecting an object that will be changed by the reload.
486486
InspectorDock::get_inspector_singleton()->update_tree();
487487

488-
// Reload script editor to revalidate GDScript if classes are added or removed.
489-
ScriptEditor::get_singleton()->reload_scripts(true);
490-
491488
// Regenerate documentation.
492489
EditorHelp::generate_doc();
493490
}

0 commit comments

Comments
 (0)