]> git.mxchange.org Git - simgear.git/commitdiff
Work around osg Registry path list problems
authortimoore <timoore>
Sun, 9 Dec 2007 22:38:10 +0000 (22:38 +0000)
committertimoore <timoore>
Sun, 9 Dec 2007 22:38:10 +0000 (22:38 +0000)
The OSG reader plugins overwrite the path list passed in options with the local
directory of the file being read, forcing you to set the path list in
the Registry. I think this a bug, but in the meantime here's a workaround.

simgear/scene/model/ModelRegistry.cxx

index b2dfa1b611d978d3e6e28967fa40a31c1fceba83..6ae694b8e6a9682355512d14c5617fbec287b3b4 100644 (file)
@@ -198,6 +198,34 @@ public:
     material->setColorMode(Material::AMBIENT_AND_DIFFUSE);
   }
 };
+
+// Work around an OSG bug - the file loaders don't use the file path
+// in options while the file is being loaded.
+
+struct OptionsPusher {
+    FilePathList localPathList;
+    OptionsPusher(const ReaderWriter::Options* options)
+    {
+        Registry* registry = Registry::instance();
+        localPathList = registry->getDataFilePathList();
+        const FilePathList& regPathList = registry->getDataFilePathList();
+        const FilePathList& optionsPathList = options->getDatabasePathList();
+        for (FilePathList::const_iterator iter = optionsPathList.begin();
+             iter != optionsPathList.end();
+             ++iter) {
+            if (find(regPathList.begin(), regPathList.end(), *iter)
+                == regPathList.end())
+                localPathList.push_front(*iter);
+        }
+        // Save the current Registry path list and install the augmented one.
+        localPathList.swap(registry->getDataFilePathList());
+    }
+    ~OptionsPusher()
+    {
+        // Restore the old path list
+        localPathList.swap(Registry::instance()->getDataFilePathList());
+    }
+};
 } // namespace
 
 ReaderWriter::ReadResult
@@ -207,9 +235,11 @@ ModelRegistry::readImage(const string& fileName,
     OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(readerMutex);
     CallbackMap::iterator iter
         = imageCallbackMap.find(getFileExtension(fileName));
+    // XXX Workaround for OSG plugin bug
+    OptionsPusher pusher(opt);
     if (iter != imageCallbackMap.end() && iter->second.valid())
         return iter->second->readImage(fileName, opt);
-    string absFileName = findDataFile(fileName, opt);
+    string absFileName = findDataFile(fileName);
     if (!fileExists(absFileName)) {
         SG_LOG(SG_IO, SG_ALERT, "Cannot find image file \""
                << fileName << "\"");
@@ -360,6 +390,8 @@ ModelRegistry::readNode(const string& fileName,
                         const ReaderWriter::Options* opt)
 {
     OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(readerMutex);
+    // XXX Workaround for OSG plugin bug.
+    OptionsPusher pusher(opt);
     Registry* registry = Registry::instance();
     ReaderWriter::ReadResult res;
     Node* cached = 0;