summaryrefslogtreecommitdiffstats
path: root/core/io/resource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/resource.cpp')
-rw-r--r--core/io/resource.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index c045c0fc74..598c99c188 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -40,7 +40,12 @@
#include <stdio.h>
void Resource::emit_changed() {
- emit_signal(CoreStringName(changed));
+ if (ResourceLoader::is_within_load() && MessageQueue::get_main_singleton() != MessageQueue::get_singleton() && !MessageQueue::get_singleton()->is_flushing()) {
+ // Let the connection happen on the call queue, later, since signals are not thread-safe.
+ call_deferred("emit_signal", CoreStringName(changed));
+ } else {
+ emit_signal(CoreStringName(changed));
+ }
}
void Resource::_resource_path_changed() {
@@ -161,12 +166,22 @@ bool Resource::editor_can_reload_from_file() {
}
void Resource::connect_changed(const Callable &p_callable, uint32_t p_flags) {
+ if (ResourceLoader::is_within_load() && MessageQueue::get_main_singleton() != MessageQueue::get_singleton() && !MessageQueue::get_singleton()->is_flushing()) {
+ // Let the check and connection happen on the call queue, later, since signals are not thread-safe.
+ callable_mp(this, &Resource::connect_changed).call_deferred(p_callable, p_flags);
+ return;
+ }
if (!is_connected(CoreStringName(changed), p_callable) || p_flags & CONNECT_REFERENCE_COUNTED) {
connect(CoreStringName(changed), p_callable, p_flags);
}
}
void Resource::disconnect_changed(const Callable &p_callable) {
+ if (ResourceLoader::is_within_load() && MessageQueue::get_main_singleton() != MessageQueue::get_singleton() && !MessageQueue::get_singleton()->is_flushing()) {
+ // Let the check and disconnection happen on the call queue, later, since signals are not thread-safe.
+ callable_mp(this, &Resource::disconnect_changed).call_deferred(p_callable);
+ return;
+ }
if (is_connected(CoreStringName(changed), p_callable)) {
disconnect(CoreStringName(changed), p_callable);
}
@@ -401,21 +416,15 @@ void Resource::_take_over_path(const String &p_path) {
}
RID Resource::get_rid() const {
- if (get_script_instance()) {
- Callable::CallError ce;
- RID ret = get_script_instance()->callp(SNAME("_get_rid"), nullptr, 0, ce);
- if (ce.error == Callable::CallError::CALL_OK && ret.is_valid()) {
- return ret;
- }
- }
- if (_get_extension() && _get_extension()->get_rid) {
- RID ret = RID::from_uint64(_get_extension()->get_rid(_get_extension_instance()));
- if (ret.is_valid()) {
- return ret;
+ RID ret;
+ if (!GDVIRTUAL_CALL(_get_rid, ret)) {
+#ifndef DISABLE_DEPRECATED
+ if (_get_extension() && _get_extension()->get_rid) {
+ ret = RID::from_uint64(_get_extension()->get_rid(_get_extension_instance()));
}
+#endif
}
-
- return RID();
+ return ret;
}
#ifdef TOOLS_ENABLED
@@ -543,11 +552,8 @@ void Resource::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_name"), "set_name", "get_name");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_scene_unique_id", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_scene_unique_id", "get_scene_unique_id");
- MethodInfo get_rid_bind("_get_rid");
- get_rid_bind.return_val.type = Variant::RID;
-
- ::ClassDB::add_virtual_method(get_class_static(), get_rid_bind, true, Vector<String>(), true);
GDVIRTUAL_BIND(_setup_local_to_scene);
+ GDVIRTUAL_BIND(_get_rid);
}
Resource::Resource() :