Fixed Helgrind issue with SceneGraph::Animator creation 44/47744/3
authorPaul Wisbey <p.wisbey@samsung.com>
Tue, 8 Sep 2015 10:12:28 +0000 (11:12 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Tue, 8 Sep 2015 12:51:36 +0000 (05:51 -0700)
Change-Id: Ieabaf8f2c7a607cdbfeea448d03ef690174642ad

dali/internal/update/animation/scene-graph-animation.cpp
dali/internal/update/animation/scene-graph-animator.h

index de9c793..a2538d1 100644 (file)
@@ -194,7 +194,9 @@ void Animation::OnDestroy(BufferIndex bufferIndex)
 
 void Animation::AddAnimator( AnimatorBase* animator )
 {
+  animator->ConnectToSceneGraph();
   animator->SetDisconnectAction( mDisconnectAction );
+
   mAnimators.PushBack( animator );
 }
 
index e96d389..e153b86 100644 (file)
@@ -71,7 +71,8 @@ public:
     mAlphaFunction(AlphaFunction::DEFAULT),
     mDisconnectAction(Dali::Animation::BakeFinal),
     mActive(false),
-    mEnabled(true)
+    mEnabled(true),
+    mConnectedToSceneGraph(false)
   {
   }
 
@@ -83,6 +84,11 @@ public:
   }
 
   /**
+   * Called when Animator is added to the scene-graph in update-thread.
+   */
+  virtual void ConnectToSceneGraph() = 0;
+
+  /**
    * Set the duration of the animator.
    * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
    * @param [in] seconds Duration in seconds.
@@ -356,6 +362,7 @@ protected:
   Dali::Animation::EndAction mDisconnectAction;     ///< EndAction to apply when target object gets disconnected from the stage.
   bool mActive:1;                                   ///< Animator is "active" while it's running.
   bool mEnabled:1;                                  ///< Animator is "enabled" while its target object is valid and on the stage.
+  bool mConnectedToSceneGraph:1;                    ///< True if ConnectToSceneGraph() has been called in update-thread.
 };
 
 /**
@@ -399,7 +406,7 @@ public:
    */
   virtual ~Animator()
   {
-    if (mPropertyOwner)
+    if (mPropertyOwner && mConnectedToSceneGraph)
     {
       mPropertyOwner->RemoveObserver(*this);
     }
@@ -411,6 +418,15 @@ public:
   }
 
   /**
+   * Called when Animator is added to the scene-graph in update-thread.
+   */
+  virtual void ConnectToSceneGraph()
+  {
+    mConnectedToSceneGraph = true;
+    mPropertyOwner->AddObserver(*this);
+  }
+
+  /**
    * Called when mPropertyOwner is connected to the scene graph.
    */
   virtual void PropertyOwnerConnected( PropertyOwner& owner )
@@ -487,7 +503,8 @@ private:
     mAnimatorFunction( animatorFunction ),
     mCurrentProgress( 0.0f )
   {
-    mPropertyOwner->AddObserver(*this);
+    // WARNING - this object is created in the event-thread
+    // The scene-graph mPropertyOwner object cannot be observed here
   }
 
   // Undefined