Fix disconnection issue of signal 10/123910/2
authorHeeyong Song <heeyong.song@samsung.com>
Fri, 7 Apr 2017 10:53:52 +0000 (19:53 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Mon, 10 Apr 2017 01:09:15 +0000 (10:09 +0900)
The item is not removed from mSignalConnections until the sinal is emitted.
Changed to remove the item if the function is not called from Emit().

Change-Id: I0288b68dac3f601790aa16e77ab78b22e437ae44

dali/public-api/signals/base-signal.cpp

index 9080179..c84393a 100644 (file)
@@ -271,10 +271,19 @@ void BaseSignal::DeleteConnection( std::size_t connectionIndex )
   SignalConnection* connection( mSignalConnections[ connectionIndex ] );
   delete connection;
 
-  // IMPORTANT - do not remove from items from mSignalConnections, set to NULL instead.
-  // Signal Emit() methods require that connection count is not reduced while iterating
-  // i.e. DeleteConnection can be called from within callbacks, while iterating through mSignalConnections.
-  mSignalConnections[ connectionIndex ] = NULL;
+  if( mEmittingFlag )
+  {
+    // IMPORTANT - do not remove from items from mSignalConnections, set to NULL instead.
+    // Signal Emit() methods require that connection count is not reduced while iterating
+    // i.e. DeleteConnection can be called from within callbacks, while iterating through mSignalConnections.
+    mSignalConnections[ connectionIndex ] = NULL;
+  }
+  else
+  {
+    // If application connects and disconnects without the signal never emitting,
+    // the mSignalConnections vector keeps growing and growing as CleanupConnections() is done from Emit.
+    mSignalConnections.Erase( mSignalConnections.Begin() + connectionIndex );
+  }
 }
 
 void BaseSignal::CleanupConnections()