diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index ce06ba7f6..16ad64d7f 100755 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -796,6 +796,13 @@ int fgInitAircraft(bool reinit, bool didUseLauncher) SGSharedPtr pkgRoot(globals->packageRoot()); SGPropertyNode* aircraftProp = fgGetNode("/sim/aircraft", true); + SGPropertyNode* aircraftDirProp = fgGetNode("/sim/aircraft-dir", true); + + // ensure aircraft-dir survives reset, so we find the same aircraft + // after a reset as we did prior to it. Without this, aircraft + // can unintentionally change on a reset + aircraftDirProp->setAttribute(SGPropertyNode::PRESERVE, true); + const string fullyQualifiedAircraftId = fgGetString("/sim/aircraft-id"); string aircraftId = fullyQualifiedAircraftId.empty() ? aircraftProp->getStringValue() : fullyQualifiedAircraftId; @@ -1404,7 +1411,6 @@ void fgStartNewReset() "Some errors restoring preserved state (read-only props?)" ); } - fgGetNode("/sim")->removeChild("aircraft-dir"); fgInitAircraftPaths(true); fgInitAircraft(true, false /* not from launcher */); diff --git a/src/Main/fg_scene_commands.cxx b/src/Main/fg_scene_commands.cxx index b79648ca8..33a950bba 100644 --- a/src/Main/fg_scene_commands.cxx +++ b/src/Main/fg_scene_commands.cxx @@ -101,6 +101,19 @@ static bool do_switch_aircraft (const SGPropertyNode * arg, SGPropertyNode * root) { fgSetString("/sim/aircraft", arg->getStringValue("aircraft")); + + // we could validate the new aircraft is find-able, and if not, bail out + // of the command at this point? Might give a better user experience? + // would need something like bool fgIsValidAircraft(name, dir); + // which could be cooked up by modifying FindAndCacheAircraft + + // We assume that we are changing the aircraft, so we remove the aircraft path. + // this forces aircraft-dir to be recomputed by a full search as the user hopefully + // expects. + // We could allow pasing the dir as an optional argument to this command, if that + // is ever needed in the future. + fgGetNode("/sim")->removeChild("aircraft-dir"); + // start a reset fgResetIdleState(); return true;