On Sun, May 23, 2010 at 3:20 PM, Martin Spott <martin.sp...@mgras.net> wrote:
> Gijs de Rooy wrote:
>
>> If you feel happy creating patches for fgviewer, here's another issue that 
>> really
>> should be looked at IMO...
>>
>> http://code.google.com/p/flightgear-bugs/issues/detail?id=117
>

I'm working on something...  My thought was that if one of the programs
had a bug in it which blocks me from my goal, I may as well push a fix
back. :)

And small is the place to start.  My patches will probably get bigger
as I get more confident with Flightgear's code, and my own code. :)

Is Terragear still being maintained?  The current version doesn't even
compile without errors.  I have a couple of fixes there.  I'll just
attach them to this message for now.  In the future, should I make
separate e-mails for each?  I will likely keep posting patches as I hit
roadblocks in my own coding (with a possibly larger patch later if my
stuff ever gets off the ground).  (I'm currently trying to troubleshoot
what may be yet another bug)

[PATCH 1/3] Fix "unable to open" messages on priorities/usgs files

Systems without write access to priorities or USGS files could not run
fgfs-construct.
This patch fixes that, so that write access to config files is no
longer required.

---
 src/BuildTiles/Clipper/priorities.cxx |    4 ++--
 src/BuildTiles/Main/usgs.cxx          |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/BuildTiles/Clipper/priorities.cxx
b/src/BuildTiles/Clipper/priorities.cxx
index f3189ef..031ae4f 100644
--- a/src/BuildTiles/Clipper/priorities.cxx
+++ b/src/BuildTiles/Clipper/priorities.cxx
@@ -31,7 +31,7 @@

 #include "priorities.hxx"

-using std::fstream;
+using std::ifstream;
 using std::string;
 using std::map;
 using std::vector;
@@ -61,7 +61,7 @@ static AreaType default_area_type;
 static AreaType sliver_target_area_type;

 int load_area_types( const std::string& filename ) {
-    fstream in ( filename.c_str() );
+    ifstream in ( filename.c_str() );

     if ( ! in ) {
         SG_LOG(SG_GENERAL, SG_ALERT, "Unable to open file " << filename);
diff --git a/src/BuildTiles/Main/usgs.cxx b/src/BuildTiles/Main/usgs.cxx
index fd464af..1c85e30 100644
--- a/src/BuildTiles/Main/usgs.cxx
+++ b/src/BuildTiles/Main/usgs.cxx
@@ -28,14 +28,14 @@

 #include "usgs.hxx"

-using std::fstream;
+using std::ifstream;
 using std::string;
 using std::vector;

 static vector<AreaType> usgs_map;

 int load_usgs_map( const std::string& filename ) {
-    fstream in ( filename.c_str() );
+    ifstream in ( filename.c_str() );

     if ( ! in ) {
         SG_LOG(SG_GENERAL, SG_ALERT, "Unable to open file " << filename);
-- 
1.7.0.1


[PATCH 2/3] Fix segfault when checking open status on a closed file

Adds pointer checking to make sure, not only that a file is open, but that
its pointer is not null (which can cause segfaults if the file isn't open).
---
 src/Lib/Array/array.cxx        |   20 ++++++++++++++------
 src/Lib/Array/array.hxx        |   23 ++++++++++++++++-------
 src/Prep/DemChop/fillvoids.cxx |    4 ++--
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/src/Lib/Array/array.cxx b/src/Lib/Array/array.cxx
index 419b28d..d06b91f 100644
--- a/src/Lib/Array/array.cxx
+++ b/src/Lib/Array/array.cxx
@@ -61,7 +61,7 @@ TGArray::TGArray( const string &file ):
     in_data = new int[ARRAY_SIZE_1][ARRAY_SIZE_1];
     // out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];

-    TGArray::open(file);
+    open(file);
 }


@@ -72,7 +72,7 @@ bool TGArray::open( const string& file_base ) {
     // open array data file
     string array_name = file_base + ".arr.gz";
     array_in = new sg_gzifstream( array_name );
-    if ( ! array_in->is_open() ) {
+    if ( !array_is_open() ) {
         cout << "  Cannot open " << array_name << endl;
         success = false;
     } else {
@@ -82,7 +82,7 @@ bool TGArray::open( const string& file_base ) {
     // open fitted data file
     string fitted_name = file_base + ".fit.gz";
     fitted_in = new sg_gzifstream( fitted_name );
-    if ( ! fitted_in->is_open() ) {
+    if ( !fitted_is_open() ) {
         // not having a .fit file is unfortunate, but not fatal.  We
         // can do a really stupid/crude fit on the fly, but it will
         // not be nearly as nice as what the offline terrafit utility
@@ -99,10 +99,18 @@ bool TGArray::open( const string& file_base ) {
 // close an Array file
 bool
 TGArray::close() {
-    // the sg_gzifstream doesn't seem to have a close()
+    if (array_is_open()) {
+        array_in->close();
+    }
+    if (fitted_is_open()) {
+        fitted_in->close();
+    }

     delete array_in;
+    array_in = NULL;
     delete fitted_in;
+    fitted_in = NULL;

     return true;
 }
@@ -113,7 +121,7 @@ TGArray::close() {
 bool
 TGArray::parse( SGBucket& b ) {
     // Parse/load the array data file
-    if ( array_in->is_open() ) {
+    if ( array_is_open() ) {
        // file open, parse
        *array_in >> originx >> originy;
        *array_in >> cols >> col_step;
@@ -160,7 +168,7 @@ TGArray::parse( SGBucket& b ) {
     }

     // Parse/load the fitted data file
-    if ( fitted_in->is_open() ) {
+    if ( fitted_is_open() ) {
         int fitted_size;
         double x, y, z;
         *fitted_in >> fitted_size;
diff --git a/src/Lib/Array/array.hxx b/src/Lib/Array/array.hxx
index 972274f..9624c27 100644
--- a/src/Lib/Array/array.hxx
+++ b/src/Lib/Array/array.hxx
@@ -82,13 +82,22 @@ public:
     // open an Array file (use "-" if input is coming from stdin)
     bool open ( const string& file_base );

-    // return if array was successfully opened or not
-    inline bool is_open() {
-      if ( array_in != NULL ) {
-       return array_in->is_open();
-      } else {
-       return false;
-      }
+    // Return whether array was successfully opened
+    bool array_is_open() {
+        if ( array_in != NULL ) {
+            return array_in->is_open();
+        } else {
+            return false;
+        }
+    }
+
+    // Return whether fitted was successfully opened
+    bool fitted_is_open() {
+        if ( fitted_in != NULL ) {
+            return fitted_in->is_open();
+        } else {
+            return false;
+        }
     }

     // close a Array file
diff --git a/src/Prep/DemChop/fillvoids.cxx b/src/Prep/DemChop/fillvoids.cxx
index d777427..8f4bfba 100644
--- a/src/Prep/DemChop/fillvoids.cxx
+++ b/src/Prep/DemChop/fillvoids.cxx
@@ -77,7 +77,7 @@ int main(int argc, char **argv) {
     TGArray src_array;
     src_array.open( tmp3 );
     src_array.parse( bucket );
-    if ( !src_array.is_open() ) {
+    if ( !src_array.array_is_open() ) {
       cout << "Unable to open source array " << tmp3 << endl;
       return -1;
     }
@@ -86,7 +86,7 @@ int main(int argc, char **argv) {
     TGArray fill_array;
     fill_array.open( tmp4.str() );
     fill_array.parse( bucket );
-    if ( !fill_array.is_open() ) {
+    if ( !fill_array.array_is_open() ) {
       cout << "no fill array, nothing to do " << tmp4.str() << endl;
       return 0;
     }
-- 
1.7.0.1


[PATCH 3/3] Fix terragear compile error

This creates the function Point3DYOrdering, which something was trying
to call, but did not exist.  This caused a compile error.  Terragear
can be compiled with this patch.  I'm still not sure whether the
function actually works, but at least it's not holding people back from
using Terragear anymore.
anymore.
---
 src/Lib/Geometry/poly_support.cxx |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/Lib/Geometry/poly_support.cxx
b/src/Lib/Geometry/poly_support.cxx
index d41d7b7..834b9a8 100644
--- a/src/Lib/Geometry/poly_support.cxx
+++ b/src/Lib/Geometry/poly_support.cxx
@@ -429,6 +429,12 @@ static void write_tree_element( TGContourNode
*node, TGPolygon& p, int hole=0) {
     }
 }

+// Compares Y coords of two points
+bool Point3DYOrdering(Point3D a, Point3D b)
+{
+    return (a[PY] < b[PY]);
+}
+
 // recurse the contour tree and build up the point inside list for
 // each contour/hole
 static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
@@ -471,7 +477,8 @@ static void calc_point_inside( TGContourNode
*node, TGPolygon &p ) {
             throw sg_exception("Polygon must have at least 2 contour points");
     }

-    sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY));
+    // Sort by y-coordinate
+    sort(allpoints.begin(), allpoints.end(), Point3DYOrdering);

     point_list::iterator point_it;

-- 
1.7.0.1

------------------------------------------------------------------------------

_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to