Fix Ref<T> self-assignment.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-09-22 17:48:22 +02:00
parent 6558de636e
commit 797efbc15b
1 changed files with 18 additions and 4 deletions

View File

@ -64,16 +64,30 @@ public:
Ref& operator=(const Ref r) Ref& operator=(const Ref r)
{ {
if ( obj ) { obj->Unref_Renamed(); obj = NULL; } if ( obj == r.Get() )
if ( (obj = r.Get()) ) obj->Refer_Renamed(); return *this;
if ( obj )
{
obj->Unref_Renamed();
obj = NULL;
}
if ( (obj = r.Get()) )
obj->Refer_Renamed();
return *this; return *this;
} }
template <class U> template <class U>
Ref operator=(const Ref<U> r) Ref operator=(const Ref<U> r)
{ {
if ( obj ) { obj->Unref_Renamed(); obj = NULL; } if ( obj == r.Get() )
if ( (obj = r.Get()) ) obj->Refer_Renamed(); return *this;
if ( obj )
{
obj->Unref_Renamed();
obj = NULL;
}
if ( (obj = r.Get()) )
obj->Refer_Renamed();
return *this; return *this;
} }