Index: trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp	(revision 139)
+++ trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp	(revision 140)
@@ -82,9 +82,9 @@
 VrpnClient_impl::~VrpnClient_impl() {
   if (!UseXbee()) {
-    // on fait une copie car le delete touche a xbee_objects_copy via
+    // on fait une copie car le delete touche a trackables_copy via
     // RemoveTrackable
-    vector<VrpnObject *> trackables_copy = trackables;
+    vector<VrpnObject_impl *> trackables_copy = trackables;
     for (unsigned int i = 0; i < trackables_copy.size(); i++)
-      delete trackables_copy.at(i);
+      delete trackables_copy.at(i)->self;
     // trackables.clear();
   } else {
@@ -114,5 +114,5 @@
 }
 
-void VrpnClient_impl::AddTrackable(VrpnObject *obj) {
+void VrpnClient_impl::AddTrackable(VrpnObject_impl *obj) {
   mutex->GetMutex();
   trackables.push_back(obj);
@@ -120,10 +120,17 @@
 }
 
-void VrpnClient_impl::RemoveTrackable(VrpnObject *obj) {
+void VrpnClient_impl::RemoveTrackable(VrpnObject_impl *obj) {
   mutex->GetMutex();
-  for (vector<VrpnObject *>::iterator it = trackables.begin();
+  for (vector<VrpnObject_impl *>::iterator it = trackables.begin();
        it < trackables.end(); it++) {
     if (*it == obj) {
       trackables.erase(it);
+      break;
+    }
+  }
+  for (vector<xbee_object>::iterator it = xbee_objects.begin();
+       it < xbee_objects.end(); it++) {
+    if ((*it).vrpnobject == obj) {
+      xbee_objects.erase(it);
       break;
     }
@@ -138,16 +145,4 @@
   mutex->GetMutex();
   xbee_objects.push_back(tmp);
-  mutex->ReleaseMutex();
-}
-
-void VrpnClient_impl::RemoveTrackable(VrpnObject_impl *obj) {
-  mutex->GetMutex();
-  for (vector<xbee_object>::iterator it = xbee_objects.begin();
-       it < xbee_objects.end(); it++) {
-    if ((*it).vrpnobject == obj) {
-      xbee_objects.erase(it);
-      break;
-    }
-  }
   mutex->ReleaseMutex();
 }
@@ -232,5 +227,5 @@
             mutex->GetMutex();
             for (unsigned int i = 0; i < trackables.size(); i++)
-                trackables.at(i)->mainloop();
+                trackables.at(i)->tracker->mainloop();
             mutex->ReleaseMutex();
         } else {
Index: trunk/lib/FlairSensorActuator/src/VrpnObject.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnObject.cpp	(revision 139)
+++ trunk/lib/FlairSensorActuator/src/VrpnObject.cpp	(revision 140)
@@ -45,5 +45,7 @@
 }
 
-VrpnObject::~VrpnObject(void) { delete pimpl_; }
+VrpnObject::~VrpnObject(void) { 
+  delete pimpl_;
+}
 
 cvmatrix *VrpnObject::Output(void) const { return pimpl_->output; }
@@ -75,6 +77,4 @@
 }
 
-void VrpnObject::mainloop(void) { pimpl_->mainloop(); }
-
 } // end namespace sensor
 } // end namespace flair
Index: trunk/lib/FlairSensorActuator/src/VrpnObject.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnObject.h	(revision 139)
+++ trunk/lib/FlairSensorActuator/src/VrpnObject.h	(revision 140)
@@ -172,5 +172,4 @@
   void UpdateFrom(const core::io_data *data){};
 
-  void mainloop(void);
   class VrpnObject_impl *pimpl_;
 };
Index: trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp	(revision 139)
+++ trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp	(revision 140)
@@ -55,5 +55,5 @@
         "identifiant pour la connexion Xbee ignore car pas en mode Xbee\n");
   }
-
+  
   // state
   cvmatrix_descriptor *desc = new cvmatrix_descriptor(7, 1);
@@ -82,8 +82,4 @@
   z_plot->AddCurve(output->Element(6));
   
-  if(parent->IsRunning()) {
-    self->Warn("adding VrpnObject on running VrpnClient can crash\n");
-  }
-  
   if (parent->UseXbee()) {
     tracker = NULL;
@@ -93,23 +89,16 @@
     tracker->register_change_handler(this, handle_pos);
     tracker->shutup = true;
-    parent->pimpl_->AddTrackable(self);
+    parent->pimpl_->AddTrackable(this);
   }
+ 
 }
 
 VrpnObject_impl::~VrpnObject_impl(void) {
-  if (tracker != NULL) // normal
-  {
-    parent->pimpl_->RemoveTrackable(self);
+  parent->pimpl_->RemoveTrackable(this);
+  if (tracker != NULL) {// normal
     tracker->unregister_change_handler(this, handle_pos);
     delete tracker;
-  } else // xbee
-  {
-    parent->pimpl_->RemoveTrackable(this);
   }
   delete plot_tab;
-}
-
-void VrpnObject_impl::mainloop(void) { 
-     tracker->mainloop();
 }
 
Index: trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h	(revision 139)
+++ trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h	(revision 140)
@@ -51,8 +51,7 @@
                   flair::core::SerialPort *serialport, uint16_t us_period);
   ~VrpnClient_impl();
-  void AddTrackable(flair::sensor::VrpnObject *obj);    // normal
-  void RemoveTrackable(flair::sensor::VrpnObject *obj); // normal
+  void AddTrackable(VrpnObject_impl *obj);    // normal
   void AddTrackable(VrpnObject_impl *obj, uint8_t id);  // xbee
-  void RemoveTrackable(VrpnObject_impl *obj);           // xbee
+  void RemoveTrackable(VrpnObject_impl *obj);           // normal+xbee
   void ComputeRotations(flair::core::Vector3D &point);
   void ComputeRotations(flair::core::Quaternion &quat);
@@ -67,5 +66,5 @@
   flair::core::Mutex *mutex;
   uint16_t us_period;
-  std::vector<flair::sensor::VrpnObject *> trackables;
+  std::vector<VrpnObject_impl *> trackables;
   typedef struct xbee_object {
     VrpnObject_impl *vrpnobject;
Index: trunk/lib/FlairSensorActuator/src/unexported/VrpnObject_impl.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/unexported/VrpnObject_impl.h	(revision 139)
+++ trunk/lib/FlairSensorActuator/src/unexported/VrpnObject_impl.h	(revision 140)
@@ -50,5 +50,4 @@
   ~VrpnObject_impl(void);
 
-  void mainloop(void);
   void GetQuaternion(flair::core::Quaternion &quaternion);
   void GetPosition(flair::core::Vector3D &point);
