Avoid constraint suicide during ObjectDestroyed callbacks 29/49329/4
authorPaul Wisbey <p.wisbey@samsung.com>
Mon, 12 Oct 2015 15:38:49 +0000 (16:38 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Mon, 12 Oct 2015 15:42:18 +0000 (16:42 +0100)
Valgrind reports this when the gallery grid layout terminates:

==5351== Invalid write of size 4
==5351==    at 0x4F8FF32: Dali::Internal::ConstraintBase::ObjectDestroyed(Dali::Internal::Object&) (constraint-base.cpp:218)
==5351==    by 0x4F962B9: Dali::Internal::Object::~Object() (object-impl.cpp:1206)
==5351==    by 0x4FA810B: Dali::Internal::CustomObject::~CustomObject() (custom-object-internal.cpp:110)

The issue is that constraints commit suicide during ObjectDestroyed callbacks,
with a (dangerous) call to mTargetObject->RemoveConstraint.

Change-Id: I8da276fda1b4dfd987a8bd699ed3d908994b361e

dali/internal/event/animation/constraint-base.cpp

index 24e41b0..f781543 100644 (file)
@@ -194,25 +194,14 @@ void ConstraintBase::ObjectDestroyed( Object& object )
   DALI_ASSERT_DEBUG( mObservedObjects.End() != iter );
   mObservedObjects.Erase( iter );
 
-  if ( &object != mTargetObject )
-  {
-    // Constraint is not useful anymore as an input-source has been destroyed
-    mSourceDestroyed = true;
-
-    // Stop observing the remaining objects
-    StopObservation();
+  // Constraint is not useful anymore as an input-source has been destroyed
+  mSourceDestroyed = true;
 
-    // Clear our sources as well
-    mSources.clear();
-
-    // We should remove ourselves from the target-object's constraints as well
-    if ( mTargetObject )
-    {
-      mTargetObject->RemoveConstraint( *this );
-    }
-  }
+  // Stop observing the remaining objects
+  StopObservation();
 
-  // NOTE: We do not clear our sources if our target-object is destroyed because we may want to clone this constraint for another target
+  // Clear our sources as well
+  mSources.clear();
 
   // Discard all object & scene-graph pointers
   mSceneGraphConstraint = NULL;