Fix crash when copying a WeakPointerTo that was already deleted

This commit is contained in:
rdb 2015-07-28 13:41:26 +02:00
parent e6d29d6f51
commit 265bf42f81
3 changed files with 16 additions and 4 deletions

View File

@ -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);
}

View File

@ -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)
{
}

View File

@ -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);
}
}
////////////////////////////////////////////////////////////////////