mirror of https://github.com/godotengine/godot
Merge pull request #22537 from Zylann/fix_objectid_leak_thread
Fix dirty read of ObjectID counter when threads are involved
This commit is contained in:
commit
36e02a0fb5
|
|
@ -2014,11 +2014,13 @@ ObjectID ObjectDB::add_instance(Object *p_object) {
|
||||||
ERR_FAIL_COND_V(p_object->get_instance_id() != 0, 0);
|
ERR_FAIL_COND_V(p_object->get_instance_id() != 0, 0);
|
||||||
|
|
||||||
rw_lock->write_lock();
|
rw_lock->write_lock();
|
||||||
instances[++instance_counter] = p_object;
|
ObjectID instance_id = ++instance_counter;
|
||||||
instance_checks[p_object] = instance_counter;
|
instances[instance_id] = p_object;
|
||||||
|
instance_checks[p_object] = instance_id;
|
||||||
|
|
||||||
rw_lock->write_unlock();
|
rw_lock->write_unlock();
|
||||||
|
|
||||||
return instance_counter;
|
return instance_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectDB::remove_instance(Object *p_object) {
|
void ObjectDB::remove_instance(Object *p_object) {
|
||||||
|
|
@ -2095,6 +2097,5 @@ void ObjectDB::cleanup() {
|
||||||
instances.clear();
|
instances.clear();
|
||||||
instance_checks.clear();
|
instance_checks.clear();
|
||||||
rw_lock->write_unlock();
|
rw_lock->write_unlock();
|
||||||
|
|
||||||
memdelete(rw_lock);
|
memdelete(rw_lock);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue