Browse Source

Fix crash when copying a WeakPointerTo that was already deleted

rdb 10 years ago
parent
commit
265bf42f81

+ 6 - 0
panda/src/express/referenceCount.I

@@ -319,6 +319,9 @@ get_weak_list() const {
 INLINE void ReferenceCount::
 weak_ref(WeakPointerToVoid *ptv) {
   TAU_PROFILE("void ReferenceCount::weak_ref()", " ", TAU_USER);
+#ifdef _DEBUG
+  nassertv(test_ref_count_integrity());
+#endif
   get_weak_list()->add_reference(ptv);
 }
 
@@ -332,6 +335,9 @@ weak_ref(WeakPointerToVoid *ptv) {
 INLINE void ReferenceCount::
 weak_unref(WeakPointerToVoid *ptv) {
   TAU_PROFILE("void ReferenceCount::weak_unref()", " ", TAU_USER);
+#ifdef _DEBUG
+  nassertv(test_ref_count_integrity());
+#endif
   nassertv(has_weak_list());
   ((WeakReferenceList *)_weak_list)->clear_reference(ptv);
 }

+ 3 - 3
panda/src/express/weakPointerTo.I

@@ -43,7 +43,7 @@ WeakPointerTo(const PointerTo<T> &copy) :
 template<class T>
 INLINE WeakPointerTo<T>::
 WeakPointerTo(const WeakPointerTo<T> &copy) :
-  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
+  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
 {
 }
 
@@ -194,7 +194,7 @@ WeakConstPointerTo(const ConstPointerTo<T> &copy) :
 template<class T>
 INLINE WeakConstPointerTo<T>::
 WeakConstPointerTo(const WeakPointerTo<T> &copy) :
-  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
+  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
 {
 }
 
@@ -206,7 +206,7 @@ WeakConstPointerTo(const WeakPointerTo<T> &copy) :
 template<class T>
 INLINE WeakConstPointerTo<T>::
 WeakConstPointerTo(const WeakConstPointerTo<T> &copy) :
-  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
+  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
 {
 }
 

+ 7 - 1
panda/src/express/weakPointerToBase.I

@@ -43,7 +43,13 @@ WeakPointerToBase(const PointerToBase<T> &copy) {
 template<class T>
 INLINE WeakPointerToBase<T>::
 WeakPointerToBase(const WeakPointerToBase<T> &copy) {
-  reassign(copy);
+  _void_ptr = copy._void_ptr;
+  _ptr_was_deleted = copy._ptr_was_deleted;
+
+  if (is_valid_pointer()) {
+    To *ptr = (To *)_void_ptr;
+    ptr->weak_ref(this);
+  }
 }
 
 ////////////////////////////////////////////////////////////////////