TextVisual - Fix a memory leak issue.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / text / text-visual.cpp
index e9278f9..31dc8bb 100644 (file)
@@ -154,18 +154,11 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS
   return geometry;
 }
 
-} // namespace
+} // unnamed namespace
 
-TextVisual::TextVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
-  mController( Text::Controller::New() ),
-  mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ),
-  mHasBeenStaged( false )
-{
-}
-
-TextVisual::~TextVisual()
+TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache )
 {
+  return new TextVisual( factoryCache );
 }
 
 void TextVisual::SetTextControlInterface( Text::ControlInterface* controlInterface )
@@ -254,10 +247,20 @@ void TextVisual::DoCreatePropertyMap( Property::Map& map ) const
   map.Insert( Toolkit::TextVisual::Property::BATCHING_ENABLED, false ); // TODO
 }
 
-void TextVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
+TextVisual::TextVisual( VisualFactoryCache& factoryCache )
+: Visual::Base( factoryCache ),
+  mController( Text::Controller::New() ),
+  mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ),
+  mHasBeenStaged( false )
 {
-  mSelf = actor;
+}
 
+TextVisual::~TextVisual()
+{
+}
+
+void TextVisual::DoSetProperties( const Property::Map& propertyMap )
+{
   for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index )
   {
     const KeyValuePair& keyValue = propertyMap.GetKeyValue( index );
@@ -807,6 +810,13 @@ Dali::Property::Value TextVisual::DoGetProperty( Dali::Property::Index index )
 
 void TextVisual::RenderText()
 {
+  Actor self = mSelf.GetHandle();
+  if( !self )
+  {
+    // Nothing to do if the handle is not initialized.
+    return;
+  }
+
   Actor renderableActor;
 
   if( mRenderer )
@@ -823,7 +833,7 @@ void TextVisual::RenderText()
       const Vector2& scrollOffset = mController->GetScrollPosition();
       renderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
 
-      mSelf.Add( renderableActor );
+      self.Add( renderableActor );
     }
     mRenderableActor = renderableActor;
 
@@ -844,6 +854,13 @@ void TextVisual::StopTextAutoScrolling()
 
 void TextVisual::SetUpAutoScrolling()
 {
+  Actor self = mSelf.GetHandle();
+  if( !self )
+  {
+    // Nothing to do if the handle is not initialized.
+    return;
+  }
+
   const Text::ScrollerData* const data = mController->GetAutoScrollData();
 
   if( NULL != data )
@@ -857,8 +874,8 @@ void TextVisual::SetUpAutoScrolling()
     mTextScroller->StartScrolling( mRenderableActor,
                                    *data );
 
-    mSelf.Add( mTextScroller->GetScrollingText() );
-    mSelf.Add( mTextScroller->GetSourceCamera() );
+    self.Add( mTextScroller->GetScrollingText() );
+    self.Add( mTextScroller->GetSourceCamera() );
   }
 }