]> git.mxchange.org Git - flightgear.git/commitdiff
Better error catching and recovery when our input sends the triangulator
authorcurt <curt>
Wed, 19 May 1999 20:01:53 +0000 (20:01 +0000)
committercurt <curt>
Wed, 19 May 1999 20:01:53 +0000 (20:01 +0000)
into never, never land.

Tools/Construct/Main/main.cxx
Tools/Construct/Parallel/client.cxx
Tools/Construct/Parallel/server.cxx

index 98bc9c76587f02162d88ac1669d9ec17a7e174f9..5923625e545355672704a12bf203ac6275c471ba 100644 (file)
 #include <sys/types.h>  // for directory reading
 #include <dirent.h>     // for directory reading
 
+#include <sys/time.h>          // set mem allocation limit
+#include <sys/resource.h>      // set mem allocation limit
+#include <unistd.h>            // set mem allocation limit
+
 #include <Bucket/newbucket.hxx>
 #include <Include/fg_constants.h>
 #include <Math/mat3.h>
@@ -393,23 +397,34 @@ void construct_tile( FGConstruct& c ) {
                 << endl;
        }
 
-       if ( (count > c.get_max_nodes()) && (error <= 1000.0) ) {
-           // increase error tolerance until number of points drops below
-           // the maximum threshold
-           cout << "produced too many nodes ..." << endl;
+       if ( count > c.get_max_nodes() ) {
+           if ( error <= 1000.0 ) {
+               // increase error tolerance until number of points drops below
+               // the maximum threshold
+               cout << "produced too many nodes ..." << endl;
            
-           acceptable = false;
-           shrinking = true;
+               acceptable = false;
+               shrinking = true;
+
+               if ( growing ) {
+                   error *= 1.25;
+                   growing = false;
+               } else {
+                   error *= 1.5;
+               }
 
-           if ( growing ) {
-               error *= 1.25;
-               growing = false;
+               cout << "Setting error to " << error << " and retrying fit." 
+                    << endl;
            } else {
-               error *= 1.5;
+               // we tried, but can't seem to get down to a
+               // reasonable number of points even with a huge error
+               // tolerance.  This could be related to the triangle()
+               // call which might be having trouble with our input
+               // set.  Let's just die hope that our parent can try
+               // again with a smaller interior triangle angle.
+               cout << "Error:  Too many nodes." << endl;
+               exit(-1);
            }
-
-           cout << "Setting error to " << error << " and retrying fit." 
-                << endl;
        }
     }
 
@@ -478,6 +493,30 @@ main(int argc, char **argv) {
        usage( argv[0] );
     }
 
+    // set mem allocation limit.  Reason: occasionally the triangle()
+    // routine can blow up and allocate memory forever.  We'd like
+    // this process to die before things get out of hand so we can try
+    // again with a smaller interior angle limit.
+    int result;
+    struct rlimit limit;
+    limit.rlim_cur = 20000000;
+    limit.rlim_max = 20000000;
+    result = setrlimit( RLIMIT_DATA, &limit );
+    cout << "result of setting mem limit = " << result << endl;
+    result = setrlimit( RLIMIT_STACK, &limit );
+    cout << "result of setting mem limit = " << result << endl;
+    result = setrlimit( RLIMIT_CORE, &limit );
+    cout << "result of setting mem limit = " << result << endl;
+    result = setrlimit( RLIMIT_RSS, &limit );
+    cout << "result of setting mem limit = " << result << endl;
+
+    // cpu time limit since occassionally the triangulator can go into
+    // and infinite loop.
+    limit.rlim_cur = 120;
+    limit.rlim_max = 120;
+    result = setrlimit( RLIMIT_CPU, &limit );
+    cout << "result of setting mem limit = " << result << endl;
+   
     // main construction data management class
     FGConstruct c;
 
index d4ca29e16eb2e8a7eb6b769e27f47dc8c8af1f35..541947bfdde75260461d44f83752090e6d9ee4c1 100644 (file)
@@ -134,7 +134,10 @@ bool construct_tile( const string& work_base, const string& output_base,
            if ( line_str == "[Finished successfully]" ) {
                fclose(fp);
                return true;
-           } else if ( line_str == "Error:  Ran out of precision at" ) {
+           } else if 
+               ( (line_str.substr(0, 31) == "Error:  Ran out of precision at")
+                 || (line_str.substr(0, 22) == "Error:  Out of memory.")
+                 || (line_str.substr(0, 23) == "Error:  Too many nodes.") ) {
                if ( angle > 9.0 ) {
                    angle = 5.0;
                    still_trying = true;
@@ -143,8 +146,16 @@ bool construct_tile( const string& work_base, const string& output_base,
                    still_trying = true;
                }
            }
+
        }
        fclose(fp);
+
+       if ( !still_trying && ( angle > 0.0 ) ) {
+           // build died for some reason ... lets try one last time
+           // with an interior angle restriction of 0
+           angle = 0.0;
+           still_trying = true;
+       }
     }
     return false;
 }
index 9ce5759cb50924948f249eb70f811d2e34869a96..66cc9b3942068afb38566350bd7d6da65d791021 100644 (file)
@@ -133,11 +133,13 @@ long int get_next_tile( const string& work_base )
 
        // reset lat
        // lat = -89.0 + (shift_up*dy) - (dy*0.5);
+       // lat = 27.0 + (0*dy) + (dy*0.5);
        lat = 15.0 + (shift_up*dy) + (dy*0.5);
 
        // reset lon
        FGBucket tmp( 0.0, lat );
        double dx = tmp.get_width();
+       // lon = -82 + (shift_over*dx) + (dx*0.5);
        lon = -180 + (shift_over*dx) + (dx*0.5);
 
        cout << "starting pass = " << pass