[Tizen] Fix some keyframes devel api crash issue 07/297707/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 21 Jun 2023 03:27:49 +0000 (12:27 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Wed, 23 Aug 2023 06:46:12 +0000 (15:46 +0900)
There was some nullptr error for some DevelKeyFrames API.

1. Let we allow to call GetKeyFrameCount even we never call Add.
2. Let we only change value if keyframe type is same as SetKeyFrameValue type.

Change-Id: I6a53648df3e19556c8462fbd4fd39340dc593373
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Animation.cpp
dali/internal/event/animation/key-frames-impl.cpp

index 1ee61ecca2e57d8a4234bc7cbf29e17e7f46936e..930a307f43e7c9ec1574d2bd3e98c9c0c03d9886 100644 (file)
@@ -9193,6 +9193,9 @@ int UtcDaliAnimationKeyFramesGetKeyFrameCountP(void)
   TestApplication application;
 
   KeyFrames keyFrames = KeyFrames::New();
+
+  DALI_TEST_EQUALS(DevelKeyFrames::GetKeyFrameCount(keyFrames), 0, TEST_LOCATION);
+
   keyFrames.Add(0.0f, Vector4(0.0f, 0.0f, 0.0f, 0.6f));
   keyFrames.Add(0.6f, Vector4(0.0f, 0.0f, 0.0f, 0.3f));
   keyFrames.Add(1.0f, Vector4(0.0f, 0.0f, 0.0f, 0.8f));
@@ -9209,14 +9212,18 @@ int UtcDaliAnimationKeyFramesGetKeyFrameP(void)
   float   inputTime  = 0.6f;
   Vector4 inputValue = Vector4(0.0f, 0.0f, 0.0f, 0.3f);
 
-  KeyFrames keyFrames = KeyFrames::New();
+  float           outputTime;
+  Property::Value outputValue;
+  KeyFrames       keyFrames = KeyFrames::New();
+
+  DevelKeyFrames::GetKeyFrame(keyFrames, 0, outputTime, outputValue);
+
+  DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::NONE, TEST_LOCATION);
+
   keyFrames.Add(0.0f, Vector4(0.0f, 0.0f, 0.0f, 0.6f));
   keyFrames.Add(inputTime, inputValue);
   keyFrames.Add(1.0f, Vector4(0.0f, 0.0f, 0.0f, 0.8f));
 
-  float           outputTime;
-  Property::Value outputValue;
-
   DevelKeyFrames::GetKeyFrame(keyFrames, 3, outputTime, outputValue);
 
   DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::NONE, TEST_LOCATION);
@@ -9265,6 +9272,17 @@ int UtcDaliAnimationKeyFramesSetKeyFrameP(void)
   DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::VECTOR4, TEST_LOCATION);
   DALI_TEST_EQUALS(outputValue.Get<Vector4>(), newValue, TEST_LOCATION);
 
+  Vector3 newUnmatchedValue = Vector3(0.0f, 1.0f, 0.2f);
+
+  // Check nothing happened if we set unmatched value type.
+  DevelKeyFrames::SetKeyFrameValue(keyFrames, 1, newUnmatchedValue);
+
+  DevelKeyFrames::GetKeyFrame(keyFrames, 1, outputTime, outputValue);
+
+  DALI_TEST_EQUALS(outputTime, inputTime, TEST_LOCATION);
+  DALI_TEST_EQUALS(outputValue.GetType(), Property::Type::VECTOR4, TEST_LOCATION);
+  DALI_TEST_EQUALS(outputValue.Get<Vector4>(), newValue, TEST_LOCATION);
+
   END_TEST;
 }
 
index e68e18cbd8cb6d66908bb5e56212196202dae5ea..2a73025ac368f323dbaa29e306b7778053fbb776 100644 (file)
@@ -166,12 +166,12 @@ Property::Value KeyFrames::GetLastKeyFrameValue() const
 
 std::size_t KeyFrames::GetKeyFrameCount() const
 {
-  return mKeyFrames->GetNumberOfKeyFrames();
+  return mKeyFrames ? mKeyFrames->GetNumberOfKeyFrames() : 0u;
 }
 
 void KeyFrames::GetKeyFrame(std::size_t index, float& time, Property::Value& value) const
 {
-  if(index < mKeyFrames->GetNumberOfKeyFrames())
+  if(mKeyFrames && index < mKeyFrames->GetNumberOfKeyFrames())
   {
     mKeyFrames->GetKeyFrameAsValue(index, time, value);
   }
@@ -179,7 +179,7 @@ void KeyFrames::GetKeyFrame(std::size_t index, float& time, Property::Value& val
 
 void KeyFrames::SetKeyFrameValue(std::size_t index, const Property::Value& value)
 {
-  if(index < mKeyFrames->GetNumberOfKeyFrames())
+  if(mKeyFrames && index < mKeyFrames->GetNumberOfKeyFrames() && mType == value.GetType())
   {
     mKeyFrames->SetKeyFrameValue(index, value);
   }