[3.0] Fix WeakHandleBase::Reset() 76/87576/1
authorXiangyin Ma <x1.ma@samsung.com>
Tue, 6 Sep 2016 14:41:54 +0000 (15:41 +0100)
committerXiangyin Ma <x1.ma@samsung.com>
Thu, 8 Sep 2016 14:50:20 +0000 (07:50 -0700)
If Reset() is called somewhere, there is no way to check whether this WeakHandle is still valid. Attempts of calling GetBaseHandle() or operator ==, != will crash.

Change-Id: I161af6539f2a9ab971a55f0e1280ed890cd98715

automated-tests/src/dali/utc-Dali-WeakHandle.cpp
dali/devel-api/object/weak-handle.cpp

index fedb2e1..9fc86a5 100644 (file)
@@ -356,6 +356,23 @@ int UtcDaliWeakHandleBaseGetBaseHandle(void)
   END_TEST;
 }
 
+int UtcDaliWeakHandleBaseReset(void)
+{
+  TestApplication application;
+  tet_infoline( "Testing Daku::WeakHandleBase::Reset()" );
+
+  Actor actor = Actor::New();
+  WeakHandleBase object(actor);
+  DALI_TEST_CHECK(object.GetBaseHandle() == actor);
+
+  object.Reset();
+
+  DALI_TEST_CHECK(object == WeakHandleBase());
+  DALI_TEST_CHECK(object.GetBaseHandle() == Handle());
+
+  END_TEST;
+}
+
 int UtcDaliWeakHandleGetHandle(void)
 {
   TestApplication application;
index eeed348..cfe628b 100644 (file)
@@ -49,9 +49,15 @@ struct WeakHandleBase::Impl : public Internal::Object::Observer
   // Destruction
   ~Impl()
   {
+    Reset();
+  }
+
+  void Reset()
+  {
     if( mObject )
     {
       mObject->RemoveObserver( *this );
+      mObject = NULL;
     }
   }
 
@@ -134,8 +140,7 @@ Handle WeakHandleBase::GetBaseHandle() const
 
 void WeakHandleBase::Reset()
 {
-  delete mImpl;
-  mImpl = NULL;
+  mImpl->Reset();
 }