Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9531)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9532)
@@ -18,4 +18,15 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2009/12/23 Thomas Bretz
+
+   * mbase/MStatusArray.[h,cc]:
+     - implemented a special treatment for TGraphs in RecursiveRemove 
+       to make sure that the fHistogram pointer doesn't get deleted
+       twice.
+     - implemented a small fix to make sure an object which is more than
+       once in a list of primitives gets really removed.
+
+
 
  2009/12/21 Thomas Bretz
Index: trunk/MagicSoft/Mars/mbase/MStatusArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusArray.cc	(revision 9531)
+++ trunk/MagicSoft/Mars/mbase/MStatusArray.cc	(revision 9532)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz 03/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2009
 !
 !
@@ -57,4 +57,6 @@
 ClassImp(MStatusArray);
 
+#include <TGraph.h>
+
 using namespace std;
 
@@ -85,7 +87,12 @@
     {
         if (!dynamic_cast<TVirtualPad*>(o) && (o->ClassName()[0]==id || id==0))
-            delete p->GetListOfPrimitives()->Remove(o);
-        else
-            RecursiveDelete(dynamic_cast<TVirtualPad*>(o), id);
+        {
+            while (p->GetListOfPrimitives()->Remove(o));
+            delete o;
+
+            continue;
+        }
+
+        RecursiveDelete(dynamic_cast<TVirtualPad*>(o), id);
     }
 
@@ -122,4 +129,50 @@
 // --------------------------------------------------------------------------
 //
+// This is a workaround to make sure that TH1 which are part of two TGraphs
+// (TGraph::GetHistogram) are not finally deleted twice. Unfortunately,
+// TGraph doesn't have it in RecursiveRemove.
+//
+void MStatusArray::RecursiveRemove(TVirtualPad *p, TObject *obj)
+{
+    if (!p)
+        return;
+
+    TIter Next(p->GetListOfPrimitives());
+    TObject *o=0;
+    while ((o=Next()))
+    {
+        if (dynamic_cast<TGraph*>(o))
+        {
+            TGraph *g = static_cast<TGraph*>(o);
+            if (g->GetHistogram()==obj)
+                g->SetHistogram(0);
+
+            continue;
+        }
+
+        RecursiveRemove(dynamic_cast<TVirtualPad*>(o), obj);
+    }
+
+}
+
+// --------------------------------------------------------------------------
+//
+// This is a workaround to make sure that TH1 which are part of two TGraphs
+// (TGraph::GetHistogram) are not finally deleted twice. Unfortunately,
+// TGraph doesn't have it in RecursiveRemove.
+//
+void MStatusArray::RecursiveRemove(TObject *obj)
+{
+    TObjArray::RecursiveRemove(obj);
+
+    TObject *o = 0;
+
+    TIter Next(this);
+    while ((o=Next()))
+        RecursiveRemove(dynamic_cast<TVirtualPad*>(o), obj);
+}
+
+// --------------------------------------------------------------------------
+//
 // Try to do a delete of the whole list in a way which is less vulnarable
 // to double deletion due to wrongly set bits or other things
Index: trunk/MagicSoft/Mars/mbase/MStatusArray.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusArray.h	(revision 9531)
+++ trunk/MagicSoft/Mars/mbase/MStatusArray.h	(revision 9532)
@@ -62,4 +62,7 @@
     void Delete(Option_t *option="");
 
+    void RecursiveRemove(TVirtualPad *p, TObject *o);
+    void RecursiveRemove(TObject *o);
+
     ClassDef(MStatusArray, 0) // Helper class for status display
 };
