(PropertyOwner) Distinguish between disconnection & destruction 42/28142/5
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 26 Sep 2014 14:52:23 +0000 (15:52 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 29 Sep 2014 10:22:09 +0000 (03:22 -0700)
There was no way to tell if the property-owner was destroyed or removed from the scene as
different operations may be required for the two scenarios.

Change-Id: If291c2dc7762e1839dbcce346620d8814f94b4d3

dali/internal/update/animation/scene-graph-animator.h
dali/internal/update/animation/scene-graph-constraint-base.h
dali/internal/update/common/property-owner.cpp
dali/internal/update/common/property-owner.h
dali/internal/update/node-attachments/scene-graph-mesh-attachment.cpp
dali/internal/update/node-attachments/scene-graph-mesh-attachment.h
dali/internal/update/nodes/node.cpp

index c7e1db0..55877b3 100644 (file)
@@ -265,6 +265,15 @@ public:
   }
 
   /**
+   * Called when mPropertyOwner is disconnected from the scene graph.
+   */
+  virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
+  {
+    mPropertyOwner = NULL;
+    mPropertyAccessor.Reset();
+  }
+
+  /**
    * Called shortly before mPropertyOwner is destroyed, along with its property.
    */
   virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
index 355b8b3..06dce2f 100644 (file)
@@ -163,22 +163,35 @@ private:
   }
 
   /**
+   * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
+   */
+  virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
+  {
+    PropertyOwnerDestroyed( owner );
+  }
+
+  /**
    * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed()
    */
   virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
   {
-    // Discard pointer to destroyed property owner
-    PropertyOwnerIter iter = mObservedOwners.find( &owner );
-    DALI_ASSERT_DEBUG( mObservedOwners.end() != iter );
-    mObservedOwners.erase( iter );
+    if ( !mDisconnected )
+    {
+      // Discard pointer to disconnected property owner
+      PropertyOwnerIter iter = mObservedOwners.find( &owner );
+      if( mObservedOwners.end() != iter )
+      {
+        mObservedOwners.erase( iter );
 
-    // Stop observing the remaining property owners
-    StopObservation();
+        // Stop observing the remaining property owners
+        StopObservation();
 
-    // Notification for derived class
-    OnDisconnect();
+        // Notification for derived class
+        OnDisconnect();
 
-    mDisconnected = true;
+        mDisconnected = true;
+      }
+    }
   }
 
   /**
index 8050bb1..19389b8 100644 (file)
@@ -41,7 +41,7 @@ PropertyOwner* PropertyOwner::New()
 
 PropertyOwner::~PropertyOwner()
 {
-  DisconnectFromSceneGraph();
+  Destroy();
 }
 
 void PropertyOwner::AddObserver(Observer& observer)
@@ -72,7 +72,7 @@ bool PropertyOwner::IsObserved()
   return mObservers.Count() != 0u;
 }
 
-void PropertyOwner::DisconnectFromSceneGraph()
+void PropertyOwner::Destroy()
 {
   // Notification for observers
   const ConstObserverIter endIter = mObservers.End();
@@ -87,6 +87,22 @@ void PropertyOwner::DisconnectFromSceneGraph()
   mConstraints.Clear();
 }
 
+void PropertyOwner::DisconnectFromSceneGraph( BufferIndex updateBufferIndex )
+{
+  // Notification for observers
+  const ConstObserverIter endIter = mObservers.End();
+  for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
+  {
+    (*iter)->PropertyOwnerDisconnected( updateBufferIndex, *this );
+  }
+
+  // Clear observers as they are not interested in destroyed if they have received a disconnect
+  mObservers.Clear();
+
+  // Remove all constraints when disconnected from scene-graph
+  mConstraints.Clear();
+}
+
 void PropertyOwner::InstallCustomProperty(PropertyBase* property)
 {
   DALI_ASSERT_DEBUG( NULL != property );
index 06e4e62..f9e0369 100644 (file)
@@ -59,7 +59,18 @@ public:
   public:
 
     /**
+     * Called when the observable object is disconnected from the scene graph.
+     * @param[in] currentBufferIndex The buffer to reset.
+     * @post The observer is automatically disconnected
+     * (observer will not receive the PropertyOwnerDestroyed callback after this)
+     */
+    virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) = 0;
+
+    /**
      * Called shortly before the observable object is destroyed.
+     *
+     * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
+     * may not be called (i.e. when shutting down).
      */
     virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
   };
@@ -97,10 +108,17 @@ public:
   bool IsObserved();
 
   /**
+   * Called just before destruction to disconnect all observers and remove constraints.
+   * This occurs when the object is in the process of being destroyed.
+   */
+  void Destroy();
+
+  /**
    * Disconnect all observers and remove constraints.
    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
+   * @param[in] currentBufferIndex The current update buffer.
    */
-  void DisconnectFromSceneGraph();
+  void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
 
   /**
    * Install a custom property.
index 11781d3..dcf471e 100644 (file)
@@ -69,6 +69,11 @@ MeshAttachment::MeshAttachment()
 {
 }
 
+void MeshAttachment::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
+{
+  // Bone node has been disconnected.
+}
+
 void MeshAttachment::PropertyOwnerDestroyed( PropertyOwner& owner )
 {
   // Bone node has been destroyed.
index ec5120a..40229a4 100644 (file)
@@ -163,6 +163,12 @@ public:
                                 BoneTransforms&           boneTransforms );
 
 private:
+
+  /**
+   * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected()
+   */
+  virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner );
+
   /**
    * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed()
    */
index 45004b5..39d6834 100644 (file)
@@ -87,7 +87,7 @@ void Node::OnDestroy()
   }
 
   // Animators, Constraints etc. should be disconnected from the child's properties.
-  PropertyOwner::DisconnectFromSceneGraph();
+  PropertyOwner::Destroy();
 }
 
 void Node::Attach( NodeAttachment& object )
@@ -252,7 +252,7 @@ void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std
   }
 
   // Animators, Constraints etc. should be disconnected from the child's properties.
-  PropertyOwner::DisconnectFromSceneGraph();
+  PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
 
   // Remove back-pointer to parent
   mParent = NULL;