From 103930bd66ec46f3a44e02412ca2273f0c7d2319 Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Fri, 7 Apr 2017 19:53:52 +0900 Subject: [PATCH] [3.0] Fix disconnection issue of signal 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: I954b7494f5063c520b91a3f39d707c4e396b2711 --- dali/public-api/signals/base-signal.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dali/public-api/signals/base-signal.cpp b/dali/public-api/signals/base-signal.cpp index 8d759e7..233981c 100644 --- a/dali/public-api/signals/base-signal.cpp +++ b/dali/public-api/signals/base-signal.cpp @@ -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() -- 2.7.4