Stop observing visuals when a control is destroyed 38/247238/3
authorHeeyong Song <heeyong.song@samsung.com>
Mon, 9 Nov 2020 07:30:18 +0000 (16:30 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 18 Nov 2020 00:51:32 +0000 (09:51 +0900)
Change-Id: I6c46f3090cfb8235ed0a081ab328d48c410f039e

automated-tests/src/dali-toolkit/utc-Dali-Control.cpp
dali-toolkit/internal/controls/control/control-data-impl.cpp

index 396bab4..ddca23f 100644 (file)
@@ -1244,3 +1244,28 @@ int UtcDaliControlDoActionWhenNotStage(void)
 
   END_TEST;
 }
+
+int UtcDaliControlStopObservingVisual(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "Test to stop observing a visual when a control is destroyed" );
+
+  Control control = Control::New();
+  control[Actor::Property::SIZE] = Vector2( 200.f, 200.f );
+  control[Control::Property::BACKGROUND] = "invalid.svg";
+
+  application.GetScene().Add( control );
+
+  application.SendNotification();
+  application.Render();
+
+  // Delete control
+  control.Unparent();
+  control.Reset();
+
+  // SVG rasterization may be finished after the control is deleted.
+  // Ensure it doesn't cause a crash.
+  DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+  END_TEST;
+}
index df01b27..9182c1f 100755 (executable)
@@ -459,6 +459,16 @@ Control::Impl::Impl( Control& controlImpl )
 
 Control::Impl::~Impl()
 {
+  for( auto&& iter : mVisuals )
+  {
+    StopObservingVisual( iter->visual );
+  }
+
+  for( auto&& iter : mRemoveVisuals )
+  {
+    StopObservingVisual( iter->visual );
+  }
+
   AccessibilityDeregister();
   // All gesture detectors will be destroyed so no need to disconnect.
   delete mStartingPinchScale;