Browse Source

Backport part of b21e8fdf3216b9a18d7f2edef9fc5ce5590f9969 that fixes an issue with geometry generation when multithreaded pipeline is enabled
Fixes bullet soft body issue as well as LP 1671639

rdb 8 years ago
parent
commit
63be56cd0e
1 changed files with 12 additions and 16 deletions
  1. 12 16
      panda/src/putil/copyOnWritePointer.cxx

+ 12 - 16
panda/src/putil/copyOnWritePointer.cxx

@@ -99,19 +99,17 @@ get_write_pointer() {
     }
 
     PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy();
+    _cow_object->CachedTypedWritableReferenceCount::cache_unref();
+    _cow_object->_lock_mutex.release();
 
-    // We can't call cache_unref_delete, because we hold the lock.
-    if (!_cow_object->CachedTypedWritableReferenceCount::cache_unref()) {
-      _cow_object->_lock_mutex.release();
-      delete _cow_object;
-    } else {
-      _cow_object->_lock_mutex.release();
-    }
+    MutexHolder holder(new_object->_lock_mutex);
     _cow_object = new_object;
-    _cow_object->cache_ref();
+    _cow_object->CachedTypedWritableReferenceCount::cache_ref();
     _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
     _cow_object->_locking_thread = current_thread;
 
+    return new_object;
+
   } else if (_cow_object->get_cache_ref_count() > 1) {
     // No one else has it specifically read-locked, but there are
     // other CopyOnWritePointers holding the same object, so we should
@@ -124,19 +122,17 @@ get_write_pointer() {
     }
 
     PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy();
+    _cow_object->CachedTypedWritableReferenceCount::cache_unref();
+    _cow_object->_lock_mutex.release();
 
-    // We can't call cache_unref_delete, because we hold the lock.
-    if (!_cow_object->CachedTypedWritableReferenceCount::cache_unref()) {
-      _cow_object->_lock_mutex.release();
-      delete _cow_object;
-    } else {
-      _cow_object->_lock_mutex.release();
-    }
+    MutexHolder holder(new_object->_lock_mutex);
     _cow_object = new_object;
-    _cow_object->cache_ref();
+    _cow_object->CachedTypedWritableReferenceCount::cache_ref();
     _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
     _cow_object->_locking_thread = current_thread;
 
+    return new_object;
+
   } else {
     // No other thread has the pointer locked, and we're the only
     // CopyOnWritePointer with this object.  We can safely write to it