From cb10f3af73ee826c307c27766629daa48c521bdf Mon Sep 17 00:00:00 2001
From: Francois Keith <keith@lirmm.fr>
Date: Wed, 19 Mar 2014 23:26:52 +0100
Subject: [PATCH] Correct signal destruction in rosPublish.

The trigger signal cannot be destroyed.
---
 src/ros_publish.cpp | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/ros_publish.cpp b/src/ros_publish.cpp
index cef0afa..3bcf22b 100644
--- a/src/ros_publish.cpp
+++ b/src/ros_publish.cpp
@@ -206,10 +206,16 @@ namespace dynamicgraph
     if(bindedSignal_.find(signal) == bindedSignal_.end())
       return;
 
+    if(signal == "trigger")
+    {
+      std::cerr << "The trigger signal should not be removed. Aborting." << std::endl;
+      return;
+    }
+
     //lock the mutex to avoid deleting the signal during a call to trigger
     while(! mutex_.try_lock() ){}
-    bindedSignal_.erase (signal);
     signalDeregistration(signal);
+    bindedSignal_.erase (signal);
     mutex_.unlock();
   }
 
@@ -226,7 +232,19 @@ namespace dynamicgraph
 
   void RosPublish::clear ()
   {
-    bindedSignal_.clear ();
+    std::map<std::string, bindedSignal_t>::iterator it = bindedSignal_.begin();
+    for(; it!= bindedSignal_.end(); )
+    {
+      if (it->first != "trigger")
+      {
+        rm(it->first);
+        it = bindedSignal_.begin();
+      }
+      else
+      {
+          ++it;
+      }
+    }
   }
 
   int& RosPublish::trigger (int& dummy, int t)
-- 
GitLab