From e23f731ef773c79fe4cbd1c994a1f12eff661259 Mon Sep 17 00:00:00 2001 From: timoore Date: Wed, 15 Aug 2007 15:22:44 +0000 Subject: [PATCH] Fix for weather interpolation problem from Anders Gidenstam 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 | 7 ++++++- src/Environment/environment_ctrl.hxx | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index aa777d288..82af0e027 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -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); +} //////////////////////////////////////////////////////////////////////// diff --git a/src/Environment/environment_ctrl.hxx b/src/Environment/environment_ctrl.hxx index d82de9da1..69b2bdf22 100644 --- a/src/Environment/environment_ctrl.hxx +++ b/src/Environment/environment_ctrl.hxx @@ -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 &table); -- 2.39.5