diff options
author | Marc Gilleron <marc.gilleron@gmail.com> | 2018-09-29 15:45:09 +0100 |
---|---|---|
committer | Marc Gilleron <marc.gilleron@gmail.com> | 2018-09-29 15:45:09 +0100 |
commit | a392d553c29079d65bab6267d35ba9a9b1af5277 (patch) | |
tree | 84cdb73f3a0bdceac34d6983af9e903d8f6c4bd7 | |
parent | 6cbdeedf57c7383827416da19b6026e3721f2812 (diff) |
Fix dirty read of ObjectID counter when threads are involved
-rw-r--r-- | core/object.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/core/object.cpp b/core/object.cpp index 86d9fbde20..345c018e6d 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -2014,11 +2014,13 @@ ObjectID ObjectDB::add_instance(Object *p_object) { ERR_FAIL_COND_V(p_object->get_instance_id() != 0, 0); rw_lock->write_lock(); - instances[++instance_counter] = p_object; - instance_checks[p_object] = instance_counter; + ObjectID instance_id = ++instance_counter; + instances[instance_id] = p_object; + instance_checks[p_object] = instance_id; + rw_lock->write_unlock(); - return instance_counter; + return instance_id; } void ObjectDB::remove_instance(Object *p_object) { @@ -2095,6 +2097,5 @@ void ObjectDB::cleanup() { instances.clear(); instance_checks.clear(); rw_lock->write_unlock(); - memdelete(rw_lock); } |