On Thu, 2008-10-23 at 09:44 +0200, James Turner wrote:
> On 23 Oct 2008, at 02:19, Csaba Halász wrote:
> 
> >
> > Of course it isn't valid, inside the function it is only setting a
> > local variable (pass by value), and it does not return anything.
> > As the _runway argument is output only, there is no reason to pass it
> > as argument. Rather, the function should have a return type of
> > FGRunway*.
> 
> Grrr - kicking myself for not seeing this, this is all because  
> FGRunway was on the stack previously, and the Mk-VIII didn't use a  
> reference for the out parameter. Returning a pointer is of course  
> cleaner, I even thought about doing that re-factoring, without  
> spotting that the our parameter was broken.
> 
> Thanks for figuring this out.
> 
> James
> 
Thanks to Csaba for helping out with the C++. This works a treat. I
attach the complete patch for fixing the MK_VIII problems. Could some
check and commit please?

Kind regards,
Alasdair
Index: mk_viii.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/mk_viii.hxx,v
retrieving revision 1.7
diff -u -r1.7 mk_viii.hxx
--- mk_viii.hxx	15 Aug 2008 18:48:12 -0000	1.7
+++ mk_viii.hxx	23 Oct 2008 14:06:13 -0000
@@ -1563,7 +1563,7 @@
 				   double to_heading);
     double get_azimuth_difference (const FGRunway *_runway);
 
-    void select_runway (const FGAirport *airport, FGRunway *_runway);
+    FGRunway* select_runway (const FGAirport *airport);
     void update_runway ();
 
     void get_bias_area_edges (Position *edge,
Index: mk_viii.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/mk_viii.cxx,v
retrieving revision 1.10
diff -u -r1.10 mk_viii.cxx
--- mk_viii.cxx	11 Sep 2008 08:38:10 -0000	1.10
+++ mk_viii.cxx	23 Oct 2008 14:06:16 -0000
@@ -4489,10 +4489,10 @@
 // This selection algorithm is not specified in [SPEC], but
 // http://www.egpws.com/general_information/description/runway_select.htm
 // talks about automatic runway selection.
-void
-MK_VIII::TCFHandler::select_runway (const FGAirport *airport,
-				    FGRunway *_runway)
+FGRunway*
+MK_VIII::TCFHandler::select_runway (const FGAirport *airport)
 {
+  FGRunway* _runway = 0;
   double min_diff = 360;
   
   for (unsigned int r=0; r<airport->numRunways(); ++r) {
@@ -4504,6 +4504,7 @@
       _runway = rwy;
     }
   } // of airport runways iteration
+  return _runway;
 }
 
 bool MK_VIII::TCFHandler::AirportFilter::pass(FGAirport *a)
@@ -4532,15 +4533,14 @@
   // the airport's reference point.
   AirportFilter filter(mk);
   const FGAirport *airport = globals->get_airports()->search(
-      mk_data(gps_latitude).get(), mk_data(gps_longitude).get(),
+      mk_data(gps_longitude).get(), mk_data(gps_latitude).get(),
 			0.5, filter);
 
   if (!airport) return;
   
 	  has_runway = true;
 
-	  FGRunway* _runway;
-	  select_runway(airport, _runway);
+	  FGRunway* _runway = select_runway(airport);
 
 	  runway.center.latitude = _runway->latitude();
 	  runway.center.longitude = _runway->longitude();
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to