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
This commit is contained in:
commit
23e51c3cb5
|
@ -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) {
|
ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
|
||||||
float progress = 0;
|
float progress = 0;
|
||||||
::ResourceLoader::ThreadLoadStatus tls = ::ResourceLoader::load_threaded_get_status(p_path, &progress);
|
::ResourceLoader::ThreadLoadStatus tls = ::ResourceLoader::load_threaded_get_status(p_path, &progress);
|
||||||
r_progress.resize(1);
|
// Default array should never be modified, it causes the hash of the method to change.
|
||||||
r_progress[0] = progress;
|
if (!ClassDB::is_default_array_arg(r_progress)) {
|
||||||
|
r_progress.resize(1);
|
||||||
|
r_progress[0] = progress;
|
||||||
|
}
|
||||||
return (ThreadLoadStatus)tls;
|
return (ThreadLoadStatus)tls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +134,7 @@ ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
|
||||||
|
|
||||||
void ResourceLoader::_bind_methods() {
|
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_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_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));
|
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;
|
String pipe;
|
||||||
int exitcode = 0;
|
int exitcode = 0;
|
||||||
Error err = ::OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr, nullptr, p_open_console);
|
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) {
|
if (err != OK) {
|
||||||
return -1;
|
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_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("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("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("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_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
|
ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
static ResourceLoader *get_singleton() { return singleton; }
|
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);
|
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_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);
|
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;
|
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 get_executable_path() const;
|
||||||
String read_string_from_stdin();
|
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);
|
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_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console = false);
|
||||||
int create_instance(const Vector<String> &p_arguments);
|
int create_instance(const Vector<String> &p_arguments);
|
||||||
|
|
|
@ -2306,4 +2306,11 @@ void ClassDB::cleanup() {
|
||||||
native_structs.clear();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#define DEFVAL(m_defval) (m_defval)
|
#define DEFVAL(m_defval) (m_defval)
|
||||||
|
#define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
|
||||||
|
|
||||||
#ifdef DEBUG_METHODS_ENABLED
|
#ifdef DEBUG_METHODS_ENABLED
|
||||||
|
|
||||||
|
@ -181,6 +182,9 @@ public:
|
||||||
};
|
};
|
||||||
static HashMap<StringName, NativeStruct> native_structs;
|
static HashMap<StringName, NativeStruct> native_structs;
|
||||||
|
|
||||||
|
static Array default_array_arg;
|
||||||
|
static bool is_default_array_arg(const Array &p_array);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Non-locking variants of get_parent_class and is_parent_class.
|
// Non-locking variants of get_parent_class and is_parent_class.
|
||||||
static StringName _get_parent_class(const StringName &p_class);
|
static StringName _get_parent_class(const StringName &p_class);
|
||||||
|
|
|
@ -803,6 +803,10 @@ bool Array::is_same_typed(const Array &p_other) const {
|
||||||
return _p->typed == p_other._p->typed;
|
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 {
|
uint32_t Array::get_typed_builtin() const {
|
||||||
return _p->typed.type;
|
return _p->typed.type;
|
||||||
}
|
}
|
||||||
|
@ -815,6 +819,12 @@ Variant Array::get_typed_script() const {
|
||||||
return _p->typed.script;
|
return _p->typed.script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array Array::create_read_only() {
|
||||||
|
Array array;
|
||||||
|
array.make_read_only();
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
void Array::make_read_only() {
|
void Array::make_read_only() {
|
||||||
if (_p->read_only == nullptr) {
|
if (_p->read_only == nullptr) {
|
||||||
_p->read_only = memnew(Variant);
|
_p->read_only = memnew(Variant);
|
||||||
|
|
|
@ -186,12 +186,14 @@ public:
|
||||||
void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
|
void set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
|
||||||
bool is_typed() const;
|
bool is_typed() const;
|
||||||
bool is_same_typed(const Array &p_other) 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;
|
uint32_t get_typed_builtin() const;
|
||||||
StringName get_typed_class_name() const;
|
StringName get_typed_class_name() const;
|
||||||
Variant get_typed_script() const;
|
Variant get_typed_script() const;
|
||||||
|
|
||||||
void make_read_only();
|
void make_read_only();
|
||||||
bool is_read_only() const;
|
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_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
|
||||||
Array(const Array &p_from);
|
Array(const Array &p_from);
|
||||||
|
|
Loading…
Reference in New Issue