From 199651ebbd8b0fa395ba4fa780d198a1125a0f37 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Jun 2016 17:06:48 +0100 Subject: [PATCH] Added handling of the possibility of null Options pointers (cherry picked from commit e3c48d9f4592e42255285f8d2de520342d048ed9) --- src/osgDB/ObjectCache.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/osgDB/ObjectCache.cpp b/src/osgDB/ObjectCache.cpp index 42fe0e752..11ca07c3a 100644 --- a/src/osgDB/ObjectCache.cpp +++ b/src/osgDB/ObjectCache.cpp @@ -18,7 +18,22 @@ using namespace osgDB; bool ObjectCache::ClassComp::operator() (const ObjectCache::FileNameOptionsPair& lhs, const ObjectCache::FileNameOptionsPair& rhs) { - return lhs.first < rhs.first || *lhs.second < *rhs.second; + // check if filename are the same + if (lhs.first < rhs.first) return true; + if (rhs.first < lhs.first) return false; + + // check if Options pointers are the same. + if (lhs.second == rhs.second) return false; + + // need to compare Options pointers + if (lhs.second.valid() && rhs.second.valid()) + { + // lhs & rhs have valid Options objects + return *lhs.second < *rhs.second; + } + + // finally use pointer comparison, expecting at least one will be NULL pointer + return lhs.second < rhs.second; } ////////////////////////////////////////////////////////////////////////////////////////////