From f1f1ec41286dcde46fd2607e0b8f8c4471096472 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Mon, 20 Feb 2012 17:45:02 -0500
Subject: [PATCH] If windowBounds file is missing, application no longer
 crashes

---
 Source/MainWindow.cpp                | 43 ++++++++++++++++------------
 Source/Processors/ProcessorGraph.cpp | 29 -------------------
 Source/UI/FilterViewport.cpp         |  2 ++
 3 files changed, 26 insertions(+), 48 deletions(-)

diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp
index 87755e8f5..d234bf003 100644
--- a/Source/MainWindow.cpp
+++ b/Source/MainWindow.cpp
@@ -92,6 +92,7 @@ void MainWindow::saveWindowBounds()
 
     File file = File("./windowState.xml");
 
+
     XmlElement* xml = new XmlElement("MAINWINDOW");
 
     XmlElement* bounds = new XmlElement("BOUNDS");
@@ -121,31 +122,35 @@ void MainWindow::loadWindowBounds()
     XmlDocument doc (file);
     XmlElement* xml = doc.getDocumentElement();
 
-    // if (xml == 0 || ! xml->hasTagName (T("MAINWINDOW")))
-    // {
-    //     delete xml;
-    //    // return "Not a valid file.";
-    // }
+    if (xml == 0 || ! xml->hasTagName (T("MAINWINDOW")))
+    {
+        
+        std::cout << "File not found." << std::endl;
+        delete xml;
+        centreWithSize (800, 600);
 
-    String description;// = T(" ");
+    } else {
 
-    forEachXmlChildElement (*xml, e)
-    {
+        String description;// = T(" ");
 
-        int x = e->getIntAttribute("x");
-        int y = e->getIntAttribute("y");
-        int w = e->getIntAttribute("w");
-        int h = e->getIntAttribute("h");
+        forEachXmlChildElement (*xml, e)
+        {
 
-        bool fs = e->getBoolAttribute("fullscreen");
+            int x = e->getIntAttribute("x");
+            int y = e->getIntAttribute("y");
+            int w = e->getIntAttribute("w");
+            int h = e->getIntAttribute("h");
 
-        // without the correction, you get drift over time
-        setTopLeftPosition(x,y-27);
-        getContentComponent()->setBounds(0,0,w,h-33);
-        //setFullScreen(fs);
+            bool fs = e->getBoolAttribute("fullscreen");
 
-    }
+            // without the correction, you get drift over time
+            setTopLeftPosition(x,y-27);
+            getContentComponent()->setBounds(0,0,w,h-33);
+            //setFullScreen(fs);
 
-    delete xml;
+        }
+
+        delete xml;
+    }
    // return "Everything went ok.";
 }
\ No newline at end of file
diff --git a/Source/Processors/ProcessorGraph.cpp b/Source/Processors/ProcessorGraph.cpp
index ed020337e..e799ffe06 100644
--- a/Source/Processors/ProcessorGraph.cpp
+++ b/Source/Processors/ProcessorGraph.cpp
@@ -407,37 +407,8 @@ void ProcessorGraph::removeProcessor(GenericProcessor* processor) {
 	
 	std::cout << "Removing processor with ID " << processor->getNodeId() << std::endl;
 
-	// GenericProcessor* source = processor->getSourceNode();
-	// GenericProcessor* dest = processor->getDestNode();
-	// int numInputs = processor->getNumInputs();
-
-	// std::cout << "  Source " << source << std::endl;
-	// std::cout << "  Dest " << dest << std::endl;
-
 	removeNode(processor->getNodeId());
 
-	// eliminate connections for now
-	/*if (dest !=0 && source !=0) {
-
-		std::cout << "   Making new connections...." << std::endl;
-
-		// connect source and dest
-		for (int chan = 0; chan < numInputs; chan++) {
-			
-			addConnection(source->getNodeId(),
-						  chan,
-						  dest->getNodeId(),
-						  chan);
-		}
-
-	}*/
-
-	// if (dest != 0)
-	// 	dest->setSourceNode(source);
-	
-	// if (source != 0)
-	// 	source->setDestNode(dest);
-
 }
 
 void ProcessorGraph::setUIComponent(UIComponent* ui)
diff --git a/Source/UI/FilterViewport.cpp b/Source/UI/FilterViewport.cpp
index ccd68d2d3..6762af913 100644
--- a/Source/UI/FilterViewport.cpp
+++ b/Source/UI/FilterViewport.cpp
@@ -1004,7 +1004,9 @@ const String FilterViewport::loadState(const File& file)
 
     if (xml == 0 || ! xml->hasTagName (T("PROCESSORGRAPH")))
     {
+        std::cout << "File not found." << std::endl;
         delete xml;
+        // don't do anything
         return "Not a valid file.";
     }
 
-- 
GitLab