Fix some keyframes devel api crash issue 35/294535/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 21 Jun 2023 03:27:49 +0000 (12:27 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 21 Jun 2023 06:33:06 +0000 (15:33 +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 22ae7f4..6e35611 100644 (file)
@@ -9361,6 +9361,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));
@@ -9377,14 +9380,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);
@@ -9433,6 +9440,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 e68e18c..2a73025 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);
   }