From e33dbca8149be986b05c5a25e0b8dff4b0b771b4 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 22 Aug 1998 14:49:55 +0000 Subject: [PATCH] Attempting to iron out seg faults and crashes. Did some shuffling to fix a initialization order problem between view position, scenery elevation. --- FDM/flight.c | 21 +++++++- LaRCsim/atmos_62.c | 14 ++++- LaRCsim/ls_interface.c | 19 ++++++- Main/GLUTmain.cxx | 7 ++- Main/fg_init.cxx | 116 ++++++++++++++++++++++++++++------------- Scenery/tile.cxx | 9 +++- Scenery/tile.hxx | 9 +++- Scenery/tilemgr.cxx | 110 ++++++++++++++++++++++++++++++++++++++ Scenery/tilemgr.hxx | 12 +++++ 9 files changed, 273 insertions(+), 44 deletions(-) diff --git a/FDM/flight.c b/FDM/flight.c index 591f9e825..455417c87 100644 --- a/FDM/flight.c +++ b/FDM/flight.c @@ -37,6 +37,7 @@ fgFLIGHT cur_flight_params; /* Initialize the flight model parameters */ int fgFlightModelInit(int model, fgFLIGHT *f, double dt) { + double save_alt = 0.0; int result; fgPrintf(FG_FLIGHT,FG_INFO,"Initializing flight model\n"); @@ -44,10 +45,21 @@ int fgFlightModelInit(int model, fgFLIGHT *f, double dt) { if ( model == FG_SLEW ) { // fgSlewInit(dt); } else if ( model == FG_LARCSIM ) { + /* lets try to avoid really screwing up the LaRCsim model */ + if ( FG_Altitude < -9000 ) { + save_alt = FG_Altitude; + FG_Altitude = 0; + } + fgFlight_2_LaRCsim(f); /* translate FG to LaRCsim structure */ fgLaRCsimInit(dt); fgPrintf( FG_FLIGHT, FG_INFO, "FG pos = %.2f\n", FG_Latitude ); fgLaRCsim_2_Flight(f); /* translate LaRCsim back to FG structure */ + + /* but lets restore our original bogus altitude when we are done */ + if ( save_alt < -9000 ) { + FG_Altitude = save_alt; + } } else { fgPrintf( FG_FLIGHT, FG_WARN, "Unimplemented flight model == %d\n", model ); @@ -101,9 +113,14 @@ int fgFlightModelSetAltitude(int model, fgFLIGHT *f, double alt_meters) { /* $Log$ -/* Revision 1.15 1998/07/30 23:44:36 curt -/* Beginning to add support for multiple flight models. +/* Revision 1.16 1998/08/22 14:49:55 curt +/* Attempting to iron out seg faults and crashes. +/* Did some shuffling to fix a initialization order problem between view +/* position, scenery elevation. /* + * Revision 1.15 1998/07/30 23:44:36 curt + * Beginning to add support for multiple flight models. + * * Revision 1.14 1998/07/12 03:08:27 curt * Added fgFlightModelSetAltitude() to force the altitude to something * other than the current altitude. LaRCsim doesn't let you do this by just diff --git a/LaRCsim/atmos_62.c b/LaRCsim/atmos_62.c index d50c98ad3..f2863a82a 100644 --- a/LaRCsim/atmos_62.c +++ b/LaRCsim/atmos_62.c @@ -213,7 +213,18 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound, { 238000., 1.18020E-07, 9.52550E+02, 2.29613E-16, -1.45786E-08 }, { 240000., 1.08270E-07, 9.47120E+02, 0.00000E+00, 0.00000E+00 } }; - + + /* for purposes of doing the table lookup, force the incoming + altitude to be >= 0 */ + + // printf("altitude = %.2f\n", altitude); + + if ( altitude < 0.0 ) { + altitude = 0.0; + } + + // printf("altitude = %.2f\n", altitude); + index = (int)( altitude / 2000 ); if (index > (MAX_ALT_INDEX-2)) { @@ -239,6 +250,7 @@ void ls_atmos( SCALAR altitude, SCALAR * sigma, SCALAR * v_sound, if (altitude < HLEV) /* BUG - these curve fits are only good to about 75000 ft */ { t_amb_r = 1. - 6.875e-6*altitude; + // printf("index = %d t_amb_r = %.2f\n", index, t_amb_r); p_amb_r = pow( t_amb_r, 5.256 ); } else diff --git a/LaRCsim/ls_interface.c b/LaRCsim/ls_interface.c index 06c025de2..4017b7c93 100644 --- a/LaRCsim/ls_interface.c +++ b/LaRCsim/ls_interface.c @@ -549,6 +549,7 @@ int fgLaRCsimInit(double dt) { /* Run an iteration of the EOM (equations of motion) */ int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) { + double save_alt = 0.0; int i; if (speedup > 0) { @@ -560,8 +561,14 @@ int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) { // run Autopilot system // fgPrintf( FG_ALL, FG_BULK, "Attempting autopilot run\n"); - fgAPRun(); + + /* lets try to avoid really screwing up the LaRCsim model */ + if ( FG_Altitude < -9000 ) { + save_alt = FG_Altitude; + FG_Altitude = 0; + } + // translate FG to LaRCsim structure fgFlight_2_LaRCsim(f); // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048); @@ -579,6 +586,11 @@ int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) { // autopilot (and the rest of the sim can use the updated // values fgLaRCsim_2_Flight(f); + + /* but lets restore our original bogus altitude when we are done */ + if ( save_alt < -9000 ) { + FG_Altitude = save_alt; + } } return(1); @@ -948,6 +960,11 @@ int ls_ForceAltitude(double alt_feet) { /* Flight Gear Modification Log * * $Log$ + * Revision 1.21 1998/08/22 14:49:56 curt + * Attempting to iron out seg faults and crashes. + * Did some shuffling to fix a initialization order problem between view + * position, scenery elevation. + * * Revision 1.20 1998/07/12 03:11:03 curt * Removed some printf()'s. * Fixed the autopilot integration so it should be able to update it's control diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index 613ea59d1..a3a176124 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -253,7 +253,7 @@ static void fgRenderFrame( void ) { // FG_Altitude * FEET_TO_METER); // this is just a temporary hack, to make me understand Pui - timerText -> setLabel (ctime (&t->cur_time)); + // timerText -> setLabel (ctime (&t->cur_time)); // end of hack // update view volume parameters @@ -872,6 +872,11 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.46 1998/08/22 14:49:56 curt +// Attempting to iron out seg faults and crashes. +// Did some shuffling to fix a initialization order problem between view +// position, scenery elevation. +// // Revision 1.45 1998/08/20 20:32:31 curt // Reshuffled some of the code in and around views.[ch]xx // diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index 21c333911..3a1726fbc 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -52,7 +52,9 @@ #include #include #include +#include #include +#include #include #include #include