Skip to content

Commit

Permalink
Merge pull request #83285 from dsnopek/gdextension-double-reload
Browse files Browse the repository at this point in the history
GDExtension: Prevent issues with the editor trying to reload GDExtensions through its usual mechanism
  • Loading branch information
akien-mga committed Oct 16, 2023
2 parents ddb7969 + 16a86b9 commit eb9903b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<GDExtension> lib;
Error err = load_gdextension_resource(p_path, lib);
if (err != OK && r_error) {
// Errors already logged in load_gdextension_resource().
*r_error = err;
// 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;
}
Expand Down
2 changes: 2 additions & 0 deletions core/extension/gdextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class GDExtension : public Resource {
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);

Expand Down

0 comments on commit eb9903b

Please sign in to comment.