From: James Turner Date: Sat, 10 Nov 2012 14:48:00 +0000 (+0000) Subject: Fix bug 905. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=08d82294bde72a2b8bbafeda030e4fce5780df24;p=flightgear.git Fix bug 905. 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. --- diff --git a/src/Airports/gnnode.cxx b/src/Airports/gnnode.cxx index 12759bc2c..1f0e13d26 100644 --- a/src/Airports/gnnode.cxx +++ b/src/Airports/gnnode.cxx @@ -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); } } diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 2db4c8987..24de0fbd3 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -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); diff --git a/src/Navaids/PositionedOctree.cxx b/src/Navaids/PositionedOctree.cxx index 261deb8be..479ee99c8 100644 --- a/src/Navaids/PositionedOctree.cxx +++ b/src/Navaids/PositionedOctree.cxx @@ -36,6 +36,7 @@ #include #include +#include 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; diff --git a/src/Navaids/positioned.hxx b/src/Navaids/positioned.hxx index a9f2cd4bf..e76ab83f6 100644 --- a/src/Navaids/positioned.hxx +++ b/src/Navaids/positioned.hxx @@ -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;