Revert "[3.0] Prevention of Null pointer dereference"
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.cpp
index 501775d..7013a10 100644 (file)
@@ -622,29 +622,34 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop
   }
 }
 
-Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue)
+Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
 {
-  Property::Index index = RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue);
-
-  /// @todo: don't keep a table of mappings per handle.
-  AddUniformMapping(index, name);
-
-  return index;
+  return RegisterProperty( name, propertyValue, Property::ANIMATABLE );
 }
 
-Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode)
+Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
 {
-  Property::Index index = Property::INVALID_INDEX;
-
-  if(Property::ANIMATABLE == accessMode)
+  // If property with the required name already exists, then just set it.
+  Property::Index index = GetPropertyIndex( name );
+  if( index != Property::INVALID_INDEX )
   {
-    index = RegisterProperty(name, propertyValue);
+    SetProperty( index, propertyValue );
   }
   else
   {
-    // Add entry to the property lookup
-    index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
-    mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
+    // Otherwise register the property
+
+    if(Property::ANIMATABLE == accessMode)
+    {
+      index = RegisterSceneGraphProperty( name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
+      AddUniformMapping( index, name );
+    }
+    else
+    {
+      // Add entry to the property lookup
+      index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
+      mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
+    }
   }
 
   return index;
@@ -754,7 +759,7 @@ void Object::DisablePropertyNotifications()
   }
 }
 
-void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName )
+void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
 {
   // Get the address of the property if it's a scene property
   const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
@@ -778,8 +783,6 @@ void Object::AddUniformMapping( Property::Index propertyIndex, const std::string
     }
   }
 
-  // @todo MESH_REWORK Store mappings for unstaged objects?
-
   if( propertyPtr != NULL )
   {
     const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
@@ -788,12 +791,10 @@ void Object::AddUniformMapping( Property::Index propertyIndex, const std::string
     {
       SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
       // Message takes ownership of Uniform map (and will delete it after copy)
-      AddUniformMapMessage( GetEventThreadServices(), *sceneObject, map);
+      AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
     }
     else
     {
-      // @todo MESH_REWORK FIXME Need to store something that can be sent to the scene
-      // object when staged.
       DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
     }
   }
@@ -1253,7 +1254,9 @@ AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index i
       if(basePropertyIndex == Property::INVALID_INDEX)
       {
         // If the property is not a component of a base property, register the whole property itself.
-        index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
+        const  std::string& propertyName = typeInfo->GetPropertyName(index);
+        RegisterSceneGraphProperty(propertyName, index, typeInfo->GetPropertyDefaultValue(index));
+        AddUniformMapping( index, propertyName );
       }
       else
       {
@@ -1262,9 +1265,11 @@ AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index i
         if(!animatableProperty)
         {
           // If the base property is not registered yet, register the base property first.
-          if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(basePropertyIndex), basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
+          const  std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
+          if(Property::INVALID_INDEX != RegisterSceneGraphProperty(basePropertyName, basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
           {
             animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
+            AddUniformMapping( basePropertyIndex, basePropertyName );
           }
         }