[Avida-SVN] r2350 - in development/source: analyze cpu

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Tue Feb 19 17:17:15 PST 2008


Author: barrick
Date: 2008-02-19 20:17:14 -0500 (Tue, 19 Feb 2008)
New Revision: 2350

Modified:
   development/source/analyze/cAnalyze.cc
   development/source/cpu/cTestCPU.cc
Log:
Added warnings and fixes for hangs caused by configuring resources in test CPU incorrectly.

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2008-02-19 22:43:54 UTC (rev 2349)
+++ development/source/analyze/cAnalyze.cc	2008-02-20 01:17:14 UTC (rev 2350)
@@ -109,6 +109,8 @@
   for (int i = 0; i < MAX_BATCHES; i++) {
     batch[i].Name().Set("Batch%d", i);
   }
+  
+  resources.clear();
 }
 
 
@@ -440,9 +442,12 @@
   // Process the resource.dat, currently assuming this is the only possible
   // input file
   ifstream resourceFile(filename, ios::in);
-  assert(resourceFile.good());
-  
-  // Read in each line of the resource file and process it
+  if ( !resourceFile.good() ) {
+    m_world->GetDriver().RaiseException("Failed to load resource file.");
+    return;
+  }
+      
+  // Read in each line of the resource file and process in
   char line[4096];
   while(!resourceFile.eof()) {
     resourceFile.getline(line, 4095);
@@ -478,7 +483,7 @@
     resources.push_back(make_pair(update, tempValues));
   }
   resourceFile.close();
-  
+
   return;
 }
 

Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2008-02-19 22:43:54 UTC (rev 2349)
+++ development/source/cpu/cTestCPU.cc	2008-02-20 01:17:14 UTC (rev 2350)
@@ -191,7 +191,7 @@
   const cResourceLib& resource_lib = m_world->GetEnvironment().GetResourceLib();
   for(int i=0; i<resource_lib.GetSize(); i++) 
   {
-    if(i >= (int)(*m_res)[which].second.size()) {
+    if( (which >= (int)m_res->size()) || (i >= (int)(*m_res)[which].second.size()) ) {
       m_resource_count.Set(i, 0.0);
     } else {
       m_resource_count.Set(i, (*m_res)[which].second[i]);




More information about the Avida-cvs mailing list