Merge pull request #83285 from dsnopek/gdextension-double-reload

GDExtension: Prevent issues with the editor trying to reload GDExtensions through its usual mechanism
This commit is contained in:
Rémi Verschelde 2023-10-16 18:44:51 +02:00
commit eb9903b4ce
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 15 additions and 5 deletions

View file

@ -35,6 +35,7 @@
#include "core/object/method_bind.h" #include "core/object/method_bind.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/version.h" #include "core/version.h"
#include "gdextension_manager.h"
extern void gdextension_setup_interface(); extern void gdextension_setup_interface();
extern GDExtensionInterfaceFunctionPtr gdextension_get_proc_address(const char *p_name); extern GDExtensionInterfaceFunctionPtr gdextension_get_proc_address(const char *p_name);
@ -949,11 +950,18 @@ 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<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
Error err = load_gdextension_resource(p_path, lib); // loading (or unloading) a GDExtension affects global data. So, we need reuse the same
if (err != OK && r_error) { // object if one has already been loaded (even if caching is disabled at the resource
// Errors already logged in load_gdextension_resource(). // loader level).
*r_error = err; 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; return lib;
} }

View file

@ -112,6 +112,8 @@ protected:
public: public:
HashMap<String, String> class_icon_paths; 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 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); static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);