From 8fdeff7aecad85ac404d70afdccd5d3dd1fc97ed Mon Sep 17 00:00:00 2001
From: Olivier Couet <Olivier.Couet@cern.ch>
Date: Fri, 6 Nov 2009 08:39:48 +0000
Subject: [PATCH] - Add a protection in case the layout went wrong.

git-svn-id: http://root.cern.ch/svn/root/trunk@31001 27541ba8-7e3a-0410-8455-c3a389f83636
---
 graf2d/gviz/inc/TGraphStruct.h   |  2 +-
 graf2d/gviz/src/TGraphStruct.cxx | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/graf2d/gviz/inc/TGraphStruct.h b/graf2d/gviz/inc/TGraphStruct.h
index 5b4e8a1f7d7..e3da3256f20 100644
--- a/graf2d/gviz/inc/TGraphStruct.h
+++ b/graf2d/gviz/inc/TGraphStruct.h
@@ -60,7 +60,7 @@ public:
    void         DumpAsDotFile(const char *filename);
    TList       *GetListOfNodes() const { return fNodes; }
    TList       *GetListOfEdges() const { return fEdges; }
-   void         Layout();
+   Int_t        Layout();
    virtual void SavePrimitive(ostream &out, Option_t *option = "");
    void         SetMargin(Double_t m=10) {fMargin = m;}
 
diff --git a/graf2d/gviz/src/TGraphStruct.cxx b/graf2d/gviz/src/TGraphStruct.cxx
index 93bf98fa2d5..5b2f280eda4 100644
--- a/graf2d/gviz/src/TGraphStruct.cxx
+++ b/graf2d/gviz/src/TGraphStruct.cxx
@@ -135,7 +135,10 @@ void TGraphStruct::DumpAsDotFile(const char *filename)
 {
    // Dump this graph structure as a "dot" file.
 
-   if (!fGVGraph) Layout();
+   if (!fGVGraph) {
+     Int_t ierr = Layout();
+     if (ierr) return;
+   }
    FILE  *file;
    file=fopen(filename,"wt");
    agwrite(fGVGraph, file);
@@ -148,7 +151,10 @@ void TGraphStruct::Draw(Option_t *option)
 {
    // Draw the graph
 
-   if (!fGVGraph) Layout();
+   if (!fGVGraph) {
+     Int_t ierr = Layout();
+     if (ierr) return;
+   }
 
    // Get the bounding box
    if (gPad) {
@@ -183,7 +189,7 @@ void TGraphStruct::Draw(Option_t *option)
 
 
 //______________________________________________________________________________
-void TGraphStruct::Layout()
+Int_t TGraphStruct::Layout()
 {
    // Layout the graph into a GraphViz data structure
 
@@ -222,7 +228,8 @@ void TGraphStruct::Layout()
    }
 
    // Layout the graph
-   gvLayout(fGVC, fGVGraph, (char*)"dot");
+   int ierr = gvLayout(fGVC, fGVGraph, (char*)"dot");
+   if (ierr) return ierr;
 
    // Layout the nodes
    if (fNodes) {
@@ -243,6 +250,8 @@ void TGraphStruct::Layout()
          edge->Layout();
       }
    }
+
+   return 0;
 }
 
 
-- 
GitLab