From 1fb1e0d143de0d345183c5d61f84c58abd36c01b Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Tue, 6 Sep 2016 15:41:54 +0100 Subject: [PATCH] [3.0] Fix WeakHandleBase::Reset() 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 | 17 +++++++++++++++++ dali/devel-api/object/weak-handle.cpp | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-WeakHandle.cpp b/automated-tests/src/dali/utc-Dali-WeakHandle.cpp index fedb2e1..9fc86a5 100644 --- a/automated-tests/src/dali/utc-Dali-WeakHandle.cpp +++ b/automated-tests/src/dali/utc-Dali-WeakHandle.cpp @@ -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; diff --git a/dali/devel-api/object/weak-handle.cpp b/dali/devel-api/object/weak-handle.cpp index eeed348..cfe628b 100644 --- a/dali/devel-api/object/weak-handle.cpp +++ b/dali/devel-api/object/weak-handle.cpp @@ -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(); } -- 2.7.4