summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-12 09:25:05 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-12 09:25:05 +0200
commit23e51c3cb563862fe9946e1838043a1f943067a5 (patch)
tree371bc591bb3855617b4e6e8f2d857632cc69dcdd /core
parent18cdfb81011969efcab0dd0725a2fc6b6fdc00fd (diff)
parent27d1fb63e11b092be812e9f1fbd8730598ae9999 (diff)
downloadredot-engine-23e51c3cb563862fe9946e1838043a1f943067a5.tar.gz
Merge pull request #92888 from Hilderin/fix-unable-to-use-resourceLoader-in-c#-after-threaded-load
Fix inability to use ResourceLoader in C# after threaded load in GDScript
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp16
-rw-r--r--core/core_bind.h4
-rw-r--r--core/object/class_db.cpp7
-rw-r--r--core/object/class_db.h4
-rw-r--r--core/variant/array.cpp10
-rw-r--r--core/variant/array.h2
6 files changed, 36 insertions, 7 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 750598ab20..b27981d56b 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -57,8 +57,11 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String &
ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
float progress = 0;
::ResourceLoader::ThreadLoadStatus tls = ::ResourceLoader::load_threaded_get_status(p_path, &progress);
- r_progress.resize(1);
- r_progress[0] = progress;
+ // Default array should never be modified, it causes the hash of the method to change.
+ if (!ClassDB::is_default_array_arg(r_progress)) {
+ r_progress.resize(1);
+ r_progress[0] = progress;
+ }
return (ThreadLoadStatus)tls;
}
@@ -131,7 +134,7 @@ ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
void ResourceLoader::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_threaded_request", "path", "type_hint", "use_sub_threads", "cache_mode"), &ResourceLoader::load_threaded_request, DEFVAL(""), DEFVAL(false), DEFVAL(CACHE_MODE_REUSE));
- ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &ResourceLoader::load_threaded_get_status, DEFVAL(Array()));
+ ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &ResourceLoader::load_threaded_get_status, DEFVAL_ARRAY);
ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &ResourceLoader::load_threaded_get);
ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE));
@@ -307,7 +310,10 @@ int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r
String pipe;
int exitcode = 0;
Error err = ::OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr, nullptr, p_open_console);
- r_output.push_back(pipe);
+ // Default array should never be modified, it causes the hash of the method to change.
+ if (!ClassDB::is_default_array_arg(r_output)) {
+ r_output.push_back(pipe);
+ }
if (err != OK) {
return -1;
}
@@ -618,7 +624,7 @@ void OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_system_font_path_for_text", "font_name", "text", "locale", "script", "weight", "stretch", "italic"), &OS::get_system_font_path_for_text, DEFVAL(String()), DEFVAL(String()), DEFVAL(400), DEFVAL(100), DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path);
ClassDB::bind_method(D_METHOD("read_string_from_stdin"), &OS::read_string_from_stdin);
- ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL(Array()), DEFVAL(false), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL_ARRAY, DEFVAL(false), DEFVAL(false));
ClassDB::bind_method(D_METHOD("execute_with_pipe", "path", "arguments", "blocking"), &OS::execute_with_pipe, DEFVAL(true));
ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
diff --git a/core/core_bind.h b/core/core_bind.h
index e4ba0e8f56..7e2686c848 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -73,7 +73,7 @@ public:
static ResourceLoader *get_singleton() { return singleton; }
Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false, CacheMode p_cache_mode = CACHE_MODE_REUSE);
- ThreadLoadStatus load_threaded_get_status(const String &p_path, Array r_progress = Array());
+ ThreadLoadStatus load_threaded_get_status(const String &p_path, Array r_progress = ClassDB::default_array_arg);
Ref<Resource> load_threaded_get(const String &p_path);
Ref<Resource> load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE);
@@ -166,7 +166,7 @@ public:
Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const;
String get_executable_path() const;
String read_string_from_stdin();
- int execute(const String &p_path, const Vector<String> &p_arguments, Array r_output = Array(), bool p_read_stderr = false, bool p_open_console = false);
+ int execute(const String &p_path, const Vector<String> &p_arguments, Array r_output = ClassDB::default_array_arg, bool p_read_stderr = false, bool p_open_console = false);
Dictionary execute_with_pipe(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true);
int create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console = false);
int create_instance(const Vector<String> &p_arguments);
diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp
index ee8c469515..9826d73a9d 100644
--- a/core/object/class_db.cpp
+++ b/core/object/class_db.cpp
@@ -2306,4 +2306,11 @@ void ClassDB::cleanup() {
native_structs.clear();
}
+// Array to use in optional parameters on methods and the DEFVAL_ARRAY macro.
+Array ClassDB::default_array_arg = Array::create_read_only();
+
+bool ClassDB::is_default_array_arg(const Array &p_array) {
+ return p_array.is_same_instance(default_array_arg);
+}
+
//
diff --git a/core/object/class_db.h b/core/object/class_db.h
index 620092a6c4..81100d7586 100644
--- a/core/object/class_db.h
+++ b/core/object/class_db.h
@@ -43,6 +43,7 @@
#include <type_traits>
#define DEFVAL(m_defval) (m_defval)
+#define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
#ifdef DEBUG_METHODS_ENABLED
@@ -181,6 +182,9 @@ public:
};
static HashMap<StringName, NativeStruct> native_structs;
+ static Array default_array_arg;
+ static bool is_default_array_arg(const Array &p_array);
+
private:
// Non-locking variants of get_parent_class and is_parent_class.
static StringName _get_parent_class(const StringName &p_class);
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index 54cd1eda2f..869499e668 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -803,6 +803,10 @@ bool Array::is_same_typed(const Array &p_other) const {
return _p->typed == p_other._p->typed;
}
+bool Array::is_same_instance(const Array &p_other) const {
+ return _p == p_other._p;
+}
+
uint32_t Array::get_typed_builtin() const {
return _p->typed.type;
}
@@ -815,6 +819,12 @@ Variant Array::get_typed_script() const {
return _p->typed.script;
}
+Array Array::create_read_only() {
+ Array array;
+ array.make_read_only();
+ return array;
+}
+
void Array::make_read_only() {
if (_p->read_only == nullptr) {
_p->read_only = memnew(Variant);
diff --git a/core/variant/array.h b/core/variant/array.h
index 3aa957b312..12824ee3f6 100644
--- a/core/variant/array.h
+++ b/core/variant/array.h
@@ -186,12 +186,14 @@ public:
void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
bool is_typed() const;
bool is_same_typed(const Array &p_other) const;
+ bool is_same_instance(const Array &p_other) const;
uint32_t get_typed_builtin() const;
StringName get_typed_class_name() const;
Variant get_typed_script() const;
void make_read_only();
bool is_read_only() const;
+ static Array create_read_only();
Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
Array(const Array &p_from);