]> git.mxchange.org Git - flightgear.git/commitdiff
Fix for weather interpolation problem from Anders Gidenstam
authortimoore <timoore>
Wed, 15 Aug 2007 15:22:44 +0000 (15:22 +0000)
committertimoore <timoore>
Wed, 15 Aug 2007 15:22:44 +0000 (15:22 +0000)
Anders said:
With Stuart's help I've looked closer at this and I think I've tracked
down the cause of the problem:
At least on my computer the sort() call on line 234 in
Environment/environment_ctrl.cxx sorts the vector entries by memory
address instead of altitude, i.e. the custom comparison predicate is not
used. This causes the tables of environment conditions to be reordered
into a wrong order at some weather updates, depending, basically,
on where the memory allocator places the objects. (Btw. why are they are
freshly allocated for each update?)

src/Environment/environment_ctrl.cxx
src/Environment/environment_ctrl.hxx

index aa777d288b2c5c7e496c9e2710bbe250bc22bd74..82af0e02725cdb0a1d263db441ce7fe8b81d17da 100644 (file)
@@ -231,7 +231,7 @@ FGInterpolateEnvironmentCtrl::read_table (const SGPropertyNode * node,
             table.push_back(b);
         }
     }
-    sort(table.begin(), table.end());
+    sort(table.begin(), table.end(), bucket::lessThan);
 }
 
 void
@@ -312,6 +312,11 @@ FGInterpolateEnvironmentCtrl::bucket::operator< (const bucket &b) const
     return (altitude_ft < b.altitude_ft);
 }
 
+bool
+FGInterpolateEnvironmentCtrl::bucket::lessThan(bucket *a, bucket *b)
+{
+    return (a->altitude_ft) < (b->altitude_ft);
+}
 
 \f
 ////////////////////////////////////////////////////////////////////////
index d82de9da16e4d85b33508aca03ffcc9bee3bf6d4..69b2bdf220d61c3c95a01512aba04dd25ffd05ac 100644 (file)
@@ -134,6 +134,8 @@ private:
         double altitude_ft;
         FGEnvironment environment;
         bool operator< (const bucket &b) const;
+        // LessThan predicate for bucket pointers.
+        static bool lessThan(bucket *a, bucket *b);
     };
 
     void read_table (const SGPropertyNode * node, vector<bucket *> &table);