From dd8270796239f088f1605bccabe30efcb0312479 Mon Sep 17 00:00:00 2001
From: buti <buti@bux.at>
Date: Wed, 27 Feb 2008 10:30:39 +0100
Subject: [PATCH] fg-patch for model-paging v0.2.1 (beta)

---
 src/AIModel/AIBase.cxx |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx
index 35be09b..bfe8d95 100644
--- a/src/AIModel/AIBase.cxx
+++ b/src/AIModel/AIBase.cxx
@@ -24,6 +24,8 @@
 #  include <config.h>
 #endif
 
+#include <unistd.h>
+
 
 #include <simgear/compiler.h>
 
@@ -157,16 +159,19 @@ void FGAIBase::Transform() {
 bool FGAIBase::init(bool search_in_AI_path) {
 
     if (!model_path.empty()) {
-
         if ( search_in_AI_path
                 && (model_path.substr(model_path.size() - 4, 4) == ".xml")) {
-            SGPath ai_path("AI");
+            SGPath ai_path(globals->get_fg_root());
+            ai_path.append("AI");
             ai_path.append(model_path);
-            try {
-                model = load3DModel( globals->get_fg_root(), ai_path.str(), props,
+            if(access(ai_path.c_str(), R_OK)==0)
+            {
+              try {
+                  model = load3DModel( globals->get_fg_root(), ai_path.str(), props,
                         globals->get_sim_time_sec() );
-            } catch (const sg_exception &e) {
-                model = NULL;
+              } catch (const sg_exception &e) {
+                  model = NULL;
+              }
             }
         } else
             model = NULL;
-- 
1.5.2.5


