diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index 92375e6b8..0b7733f6d 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -3842,7 +3842,10 @@ struct DerefLessFunctor { bool operator () (const T& lhs, const T& rhs) { - return (lhs.valid() && rhs.valid()) && (lhs->getSortValue() > rhs->getSortValue()); + if (!lhs || !rhs) return lhsgetLayer() < rhs->getLayer()) return true; + if (rhs->getLayer() < lhs->getLayer()) return false; + return (lhs->getSortValue() > rhs->getSortValue()); } };