From 579b60b8e45363bc1ae011f67196d73ef392620a Mon Sep 17 00:00:00 2001 From: timoore Date: Tue, 11 Dec 2007 11:10:35 +0000 Subject: [PATCH] Check if scenery is available before blowing away existing values in ground cache This fixes a race condition when teleporting somewhere outside of the currently loaded scenery. Before, if there was no valid scenery, an aircraft might end up at the center of the earth... --- src/FDM/groundcache.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/FDM/groundcache.cxx b/src/FDM/groundcache.cxx index 575cd8435..dfec899cf 100644 --- a/src/FDM/groundcache.cxx +++ b/src/FDM/groundcache.cxx @@ -476,8 +476,15 @@ FGGroundCache::prepare_ground_cache(double ref_time, const SGVec3d& pt, double rad) { // Empty cache. - ground_radius = 0.0; found_ground = false; + SGGeod geodPt = SGGeod::fromCart(pt); + // Don't blow away the cache ground_radius and stuff if there's no + // scenery + if (!globals->get_tile_mgr()->scenery_available(geodPt.getLatitudeDeg(), + geodPt.getLongitudeDeg(), + rad)) + return false; + ground_radius = 0.0; triangles.resize(0); catapults.resize(0); wires.resize(0); @@ -489,7 +496,7 @@ FGGroundCache::prepare_ground_cache(double ref_time, const SGVec3d& pt, cache_ref_time = ref_time; // Get a normalized down vector valid for the whole cache - SGQuatd hlToEc = SGQuatd::fromLonLat(SGGeod::fromCart(pt)); + SGQuatd hlToEc = SGQuatd::fromLonLat(geodPt); down = hlToEc.rotate(SGVec3d(0, 0, 1)); // Prepare sphere around the aircraft. -- 2.39.5