GDExtension: Prevent issues with the editor trying to reload GDExtensions through its usual mechanism

This commit is contained in:
David Snopek 2023-10-13 12:54:21 -05:00
parent 51f81e1c88
commit 16a86b9604
2 changed files with 15 additions and 5 deletions

View File

@ -35,6 +35,7 @@
#include "core/object/method_bind.h"
#include "core/os/os.h"
#include "core/version.h"
#include "gdextension_manager.h"
extern void gdextension_setup_interface();
extern GDExtensionInterfaceFunctionPtr gdextension_get_proc_address(const char *p_name);
@ -949,12 +950,19 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path,
}
Ref<Resource> GDExtensionResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
Ref<GDExtension> lib;
// We can't have two GDExtension resource object representing the same library, because
// loading (or unloading) a GDExtension affects global data. So, we need reuse the same
// object if one has already been loaded (even if caching is disabled at the resource
// loader level).
GDExtensionManager *manager = GDExtensionManager::get_singleton();
Ref<GDExtension> lib = manager->get_extension(p_path);
if (lib.is_null()) {
Error err = load_gdextension_resource(p_path, lib);
if (err != OK && r_error) {
// Errors already logged in load_gdextension_resource().
*r_error = err;
}
}
return lib;
}

View File

@ -112,6 +112,8 @@ protected:
public:
HashMap<String, String> class_icon_paths;
virtual bool editor_can_reload_from_file() override { return false; } // Reloading is handled in a special way.
static String get_extension_list_config_file();
static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);