|
@@ -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;
|
|
|
|
- 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;
|
|
return lib;
|
|
}
|
|
}
|