]> git.mxchange.org Git - flightgear.git/commitdiff
Deterministic loading sequence for Nasal scripts
authorThorstenB <brehmt@gmail.com>
Sun, 29 May 2011 16:44:15 +0000 (18:44 +0200)
committerThorstenB <brehmt@gmail.com>
Sun, 29 May 2011 16:44:15 +0000 (18:44 +0200)
Avoid loading Nasal scripts in (random) file system order

src/Scripting/NasalSys.cxx

index 62a2b261cfff44cfd003d7e4bb96052acffdc83d..2690bda6dda8139f635093602909317f8dbb3e5f 100644 (file)
@@ -805,10 +805,19 @@ void FGNasalSys::update(double)
     _context = naNewContext();
 }
 
+bool pathSortPredicate(const SGPath& p1, const SGPath& p2)
+{
+  return p1.file() < p2.file();
+}
+
 // Loads all scripts in given directory 
 void FGNasalSys::loadScriptDirectory(simgear::Dir nasalDir)
 {
     simgear::PathList scripts = nasalDir.children(simgear::Dir::TYPE_FILE, ".nas");
+    // sort scripts, avoid loading sequence effects due to file system's
+    // random directory order
+    std::sort(scripts.begin(), scripts.end(), pathSortPredicate);
+
     for (unsigned int i=0; i<scripts.size(); ++i) {
       SGPath fullpath(scripts[i]);
       SGPath file = fullpath.file();