]> Creatis software - bbtk.git/commitdiff
Nasty bug fix !
authorguigues <guigues>
Wed, 12 Nov 2008 15:42:52 +0000 (15:42 +0000)
committerguigues <guigues>
Wed, 12 Nov 2008 15:42:52 +0000 (15:42 +0000)
The 'global execution list' collected black box pointers (i.e. boost::shared_ptr<BlackBox*>) and if it was not reprocessed and thus cleared before exit then BlackBoxes might not be automatically deleted (ref count still > 0). Changed the pointers with weak pointers and correctly checked that they are still valid before using them.
This fixed very nasty bugs in which commands like 'connect A.BoxChange B.BoxExecute' for WxBlackBoxes created apparently random leaks on exit (depending on the order the windows were closed or if they were touched !)

kernel/src/bbtkBlackBox.cxx

index c21285c..859430f 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/10/17 08:18:12 $
-  Version:   $Revision: 1.25 $
+  Date:      $Date: 2008/11/12 15:42:52 $
+  Version:   $Revision: 1.26 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -50,7 +50,7 @@ namespace bbtk
 
   static bool bbmgSomeBoxExecuting = false;
   static bool bbmgFreezeExecution = false;
-  static std::set<BlackBox::Pointer> bbmgExecutionList;
+  static std::set<BlackBox::WeakPointer> bbmgExecutionList;
 
   //=========================================================================
   BlackBox::Deleter::Deleter()
@@ -1135,14 +1135,24 @@ namespace bbtk
                         "=> BlackBox::bbGlobalProcessExecutionList()"
                         <<std::endl);     
      
-     std::set<BlackBox::Pointer>::iterator i;
+     std::set<BlackBox::WeakPointer>::iterator i;
      for (i=bbmgExecutionList.begin();
          i!=bbmgExecutionList.end();
          ++i)
        {
-        bbtkDebugMessage("process",4,
-                         " -> Executing "<<(*i)->bbGetFullName()<<std::endl);
-        (*i)->bbExecute(true);
+        {
+          if ((*i).lock())
+            {
+              bbtkDebugMessage("process",4,
+                               " -> Executing "<<
+                               (*i).lock()->bbGetFullName()<<std::endl);
+              (*i).lock()->bbExecute(true);
+            }
+          else 
+            {
+              bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
+            }
+        }
        }
      
      bbmgExecutionList.clear();