Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Merge pull request #122916 from Ivorforce/gdtype-owning-thread

Thaddeus Crews2a8c7de9faf6
diff --cc core/object/gdtype.cpp
index 6cda72382d4,1347e4b1adb..609154e3e25
--- a/core/object/gdtype.cpp
+++ b/core/object/gdtype.cpp
@@@ -68,24 -70,30 +70,30 @@@ GDType::~GDType()
void GDType::initialize() {
ERR_FAIL_COND(init_state != InitState::UNINITIALIZED);
+ owning_thread_id = Thread::get_caller_id();
if (super_type) {
- // Now that a subtype is registered, the supertype cannot change anymore.
- // Otherwise, our caches would become invalid.
- // This shouldn't be a problem, since classes should register all their
- // parts in _bind_methods, which is called on registration.
- super_type->init_state = InitState::FINALIZED;
+ if (super_type->init_state != InitState::FINALIZED) {
+ if (super_type->owning_thread_id != Thread::get_caller_id()) {
+ WARN_PRINT("Finalizing a GDType from a subtype from another thread.");
+ }
+ // Now that a subtype is registered, the supertype cannot change anymore.
+ // Otherwise, our caches would become invalid.
+ // This shouldn't be a problem, since classes should register all their
+ // parts in _bind_methods, which is called on registration.
+ super_type->init_state = InitState::FINALIZED;
+ }
- property_map = super_type->property_map;
+ _members = super_type->_members;
}
init_state = InitState::MUTABLE;
}
void GDType::bind_integer_constant(const StringName &p_enum, const StringName &p_name, int64_t p_constant, bool p_is_bitfield) {
- ERR_FAIL_COND(!Thread::is_main_thread());
+ ERR_FAIL_COND(Thread::get_caller_id() != owning_thread_id);
ERR_FAIL_COND(init_state != InitState::MUTABLE);
- ERR_FAIL_COND_MSG(property_map.has(p_name), vformat("Object '%s' already has property '%s'.", get_name(), p_name));
+ ERR_FAIL_COND_MSG(_members.has(p_name), vformat("Object '%s' already has member '%s'.", get_name(), p_name));
EnumInfo *enum_info = nullptr;
@@@ -140,10 -148,10 +148,10 @@@ void GDType::add_signal(MethodInfo p_si
}
bool GDType::bind_method(MethodBind *p_method, bool p_take_ownership) {
- ERR_FAIL_COND_V(!Thread::is_main_thread(), false);
+ ERR_FAIL_COND_V(Thread::get_caller_id() != owning_thread_id, false);
ERR_FAIL_COND_V(init_state != InitState::MUTABLE, false);
- if (property_map.has(p_method->get_name())) {
+ if (_members.has(p_method->get_name())) {
if (p_take_ownership) {
memdelete(p_method);
}
@@@ -160,14 -168,14 +168,14 @@@
}
void GDType::set_method_flags(const StringName &p_method, int p_flags) {
- ERR_FAIL_COND(!Thread::is_main_thread());
+ ERR_FAIL_COND(Thread::get_caller_id() != owning_thread_id);
ERR_FAIL_COND(init_state != InitState::MUTABLE);
- const Property *property = self_property_map.getptr(p_method);
- ERR_FAIL_NULL(property);
- ERR_FAIL_COND(property->type != Property::Type::METHOD);
+ const Member *member = _self_members.getptr(p_method);
+ ERR_FAIL_NULL(member);
+ ERR_FAIL_COND(member->type != Member::Type::METHOD);
- const_cast<MethodBind *>(property->payload.method)->set_hint_flags(p_flags);
+ const_cast<MethodBind *>(member->payload.method)->set_hint_flags(p_flags);
}
bool GDType::bind_compatibility_method(MethodBind *p_method) {
@@@ -183,10 -191,10 +191,10 @@@
void GDType::add_property(const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter,
int p_index) {
- ERR_FAIL_COND(!Thread::is_main_thread());
+ ERR_FAIL_COND(Thread::get_caller_id() != owning_thread_id);
ERR_FAIL_COND(init_state != InitState::MUTABLE);
- ERR_FAIL_COND_MSG(property_map.has(p_pinfo.name), vformat("Object '%s' already has property '%s'.", get_name(), p_pinfo.name));
+ ERR_FAIL_COND_MSG(_members.has(p_pinfo.name), vformat("Object '%s' already has member '%s'.", get_name(), p_pinfo.name));
const MethodBind *mb_set = nullptr;
if (p_setter) {