]> git.mxchange.org Git - flightgear.git/commitdiff
Fix bug 905.
authorJames Turner <zakalawe@mac.com>
Sat, 10 Nov 2012 14:48:00 +0000 (14:48 +0000)
committerJames Turner <zakalawe@mac.com>
Sat, 10 Nov 2012 14:48:00 +0000 (14:48 +0000)
When a position is modified for an in-cache FGPositioned, we need to update the runtime information too, or the Octree code may (rightly) complain that it's seeing inconsistent data. Also make the Octree check an exception throw, and verbose, so this is easier to detect in the future.

src/Airports/gnnode.cxx
src/Navaids/NavDataCache.cxx
src/Navaids/PositionedOctree.cxx
src/Navaids/positioned.hxx

index 12759bc2cdda0211aa3d24fab174e5add7cf6c87..1f0e13d26077c6cf22632db834f76599083cd5df 100644 (file)
@@ -40,8 +40,10 @@ double FGTaxiNode::getElevationFt()
     double elevationEnd = -100;
     if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
       
-      mPosition.setElevationM(elevationEnd);
-      NavDataCache::instance()->updatePosition(guid(), mPosition);
+      SGGeod newPos = mPosition;
+      newPos.setElevationM(elevationEnd);
+    // this will call modifyPosition to update mPosition
+      NavDataCache::instance()->updatePosition(guid(), newPos);
     }
   }
   
index 2db4c89878697dcf422af3a88ee1337ab43de3f8..24de0fbd3fda5429fb882cae48e35085af7322fa 100644 (file)
@@ -1337,6 +1337,11 @@ PositionedID NavDataCache::insertAirport(FGPositioned::Type ty, const string& id
   
 void NavDataCache::updatePosition(PositionedID item, const SGGeod &pos)
 {
+  if (d->cache.find(item) != d->cache.end()) {
+    SG_LOG(SG_GENERAL, SG_DEBUG, "updating position of an item in the cache");
+    d->cache[item]->modifyPosition(pos);
+  }
+  
   SGVec3d cartPos(SGVec3d::fromGeod(pos));
   
   d->reset(d->setAirportPos);
index 261deb8beb29227b54652eaee7b2a6597e1eb211..479ee99c83486cb753ecfd89d2720fab6ff8e283 100644 (file)
@@ -36,6 +36,7 @@
 #include <boost/foreach.hpp>
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/structure/exception.hxx>
 
 namespace flightgear
 {
@@ -66,7 +67,22 @@ void Leaf::visit(const SGVec3d& aPos, double aCutoff,
   
   for (; it != end; ++it) {
     FGPositioned* p = cache->loadById(it->second);
-    assert(intersects(_box, p->cart()));
+    if (!intersects(_box, p->cart())) {
+        // see http://code.google.com/p/flightgear-bugs/issues/detail?id=905
+      
+      SG_LOG(SG_GENERAL, SG_WARN, "XXXXXXXXX bad spatial index for " << it->second
+             << "; " << p->ident() << " of type " <<
+             FGPositioned::nameForType(p->type()));
+      SG_LOG(SG_GENERAL, SG_WARN, "\tgeodetic location:" << p->geod());
+      SG_LOG(SG_GENERAL, SG_WARN, "\tcartesian location:" << p->cart());
+      
+      SG_LOG(SG_GENERAL, SG_WARN, "leaf box:" <<
+             _box.getMin() << " x " << _box.getMax());
+      
+      throw sg_exception("Bad spatial index data");
+    }
+    
+    
     double d = dist(aPos, p->cart());
     if (d > aCutoff) {
       continue;
index a9f2cd4bf8decd2c1badb65bba405096a870f033..e76ab83f674ddafc618a237d13291605a1a588b9 100644 (file)
@@ -229,7 +229,7 @@ protected:
   void modifyPosition(const SGGeod& newPos);
   
   const PositionedID mGuid;
-  SGGeod mPosition;
+  const SGGeod mPosition;
   const SGVec3d mCart;
   const Type mType;
   const std::string mIdent;