Skip to content

Commit 43e673d

Browse files
committed
ref pointers
TODO: Cleanup WeakRefBase lifetime is now controlled by a shared_ptr and a control block objects now act like shared and weakptrs so they free themselves without any outside involvement, last of an objects reference goes out of scope object deletes.
1 parent f1f09ef commit 43e673d

4 files changed

Lines changed: 168 additions & 166 deletions

File tree

Engine/source/console/simObject.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,17 +1053,17 @@ class SimObjectPtr : public WeakRefPtr< T >
10531053

10541054
typedef WeakRefPtr< T > Parent;
10551055

1056-
SimObjectPtr() {}
1057-
SimObjectPtr(T *ptr) { this->mReference = NULL; set(ptr); }
1058-
SimObjectPtr( const SimObjectPtr& ref ) { this->mReference = NULL; set(ref.mReference); }
1056+
SimObjectPtr() = default;
1057+
SimObjectPtr(T *ptr) { set(ptr); }
1058+
SimObjectPtr( const SimObjectPtr& ref ) { this->mReference = ref.mReference; }
10591059

10601060
T* getObject() const { return Parent::getPointer(); }
10611061

1062-
~SimObjectPtr() { set((WeakRefBase::WeakReference*)NULL); }
1062+
~SimObjectPtr() { mReference = NULL; }
10631063

10641064
SimObjectPtr<T>& operator=(const SimObjectPtr ref)
10651065
{
1066-
set(ref.mReference);
1066+
mReference = ref.mReference;
10671067
return *this;
10681068
}
10691069
SimObjectPtr<T>& operator=(T *ptr)
@@ -1073,31 +1073,10 @@ class SimObjectPtr : public WeakRefPtr< T >
10731073
}
10741074

10751075
protected:
1076-
void set(WeakRefBase::WeakReference * ref)
1077-
{
1078-
if( ref == this->mReference )
1079-
return;
1080-
1081-
if( this->mReference )
1082-
{
1083-
// Auto-delete
1084-
T* obj = this->getPointer();
1085-
if ( this->mReference->getRefCount() == 2 && obj && obj->isAutoDeleted() )
1086-
obj->deleteObject();
1087-
1088-
this->mReference->decRefCount();
1089-
}
1090-
this->mReference = NULL;
1091-
if( ref )
1092-
{
1093-
this->mReference = ref;
1094-
this->mReference->incRefCount();
1095-
}
1096-
}
10971076

10981077
void set(T * obj)
10991078
{
1100-
set(obj ? obj->getWeakReference() : (WeakRefBase::WeakReference *)NULL);
1079+
mReference = obj ? obj->getWeakReference() : nullptr;
11011080
}
11021081
};
11031082

Engine/source/core/util/refBase.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
WeakRefBase::~WeakRefBase()
44
{
55
if (mControl)
6-
mControl->object = nullptr;
6+
mControl->object = NULL;
77
}
88

99
WeakControlBlock::WeakControlBlock(WeakRefBase* obj)
@@ -15,3 +15,7 @@ WeakControlBlock::~WeakControlBlock()
1515
{
1616

1717
}
18+
19+
WeakRefBase::WeakReference::~WeakReference()
20+
{
21+
}

0 commit comments

Comments
 (0)